C# QR Kodu Oluşturucu Uygulaması
IronQR, Iron Software'ın yepyeni .NET QR Kodu kütüphanesidir. Modern makine öğrenimi tekniklerini kullanarak QR kodlarını yüksek doğrulukla herhangi bir açıdan okuyun. Yeni QR kodlarını kolayca oluşturun ve özelleştirin! IronQR ile hemen başlayın!
C# kullanarak QR kodları oluşturma rehberimize hoş geldiniz! QR kodları ve .NET barkod DLL dosyaları, bilgiyi hızlı ve verimli bir şekilde paylaşmanın popüler yolları haline geldi. İster bir uygulama geliştiriyor olun, ister bir web sitesi yönetiyor olun, ister bağlantıları paylaşmanın pratik bir yolunu arıyor olun, bu kodlar son derece kullanışlı olabilir. Bu rehberde, QR kodlarını IronQR kullanarak etkili bir şekilde nasıl oluşturacağınızı göstereceğiz, böylece ihtiyaçlarınıza göre QR kodları üretebilirsiniz. Bu kütüphane, C# ile çalışan herkes için karmaşık işlemlerle uğraşmadan QR kodları oluşturmayı kolaylaştırır. Başlamak için gereken tüm bilgileri sunarak size adım adım rehberlik edeceğiz. Uygulamanıza QR kodu oluşturma işlevi eklemek istiyorsanız veya yalnızca bunun nasıl yapıldığını merak ediyorsanız doğru yerdesiniz. Başlayalım.
C# ile QR Kodu Oluşturucu Nasıl Geliştirilir
- Visual Studio'da bir Windows Forms Uygulaması Oluşturun
- NuGet kullanarak QR Kütüphanesini Yükleyin
- Formun arayüz öğelerini tasarlayın
- QR kodu oluşturma mantığını yazın
- Uygulamayı çalıştırın ve QR kodlarını oluşturmaya başlayın
C# için QR Kodu Oluşturucu Kütüphanesini Yükleyin
IronQR'u projenizde kullanmaya bugün ücretsiz deneme sürümüyle başlayın.
Başlamadan önce, IronQR NuGet Paketini yüklememiz gerekiyor.
IronQR: C# QR Kütüphanesi
IronQR, .NET uygulamalarına QR kod işlevselliğini entegre etmek için bir C# QR Kod kütüphanesidir. IronQR, Windows, Linux, macOS, iOS ve Android gibi çeşitli geliştirme ortamlarında uyumluluğu sağlamak için C#, VB.NET, F#, .NET Core, .NET Standard, .NET Framework gibi çok çeşitli .NET sürümlerini ve proje türlerini destekler.
IronQR, QR kodlarını okuma ve QR kodları oluşturma, birden fazla görüntü formatını destekleme ve QR kodlarına yeniden boyutlandırma, stil verme ve logolar ekleme gibi özelleştirme seçenekleri sunan gelişmiş özellikleriyle öne çıkar.
IronQR'nin Bazı Ana Özellikleri
IronQR, temel QR kodu oluşturmanın ötesine geçerek QR kodlarıyla ilgili çok çeşitli görevler için tasarlanmış özellikler sunar. Bu özellikleri ve konsol uygulamaları gibi her tür .NET uygulama şablonuna entegre edebileceğiniz örnek kodlarını inceleyelim.
QR Kodlarını Okuyun
IronQR, QR kodlarını çözümleyerek içerdikleri bilgilere kolayca erişmenizi sağlar. Basit URL'lerden karmaşık gömülü bilgilere kadar QR kodlarındaki verileri hızlı ve doğru bir şekilde çıkarabilirsiniz.
using IronQr;
using IronSoftware.Drawing;
using System;
using System.Collections.Generic;
IronQr.License.LicenseKey = "License-Key";
// Load the image file that contains the QR Code
var inputImage = AnyBitmap.FromFile("QRCode.png");
// Prepare the image for QR code detection
QrImageInput qrInput = new QrImageInput(inputImage);
// Initialize the QR Code reader
QrReader qrReader = new QrReader();
// Execute QR Code reading on the provided image
IEnumerable<QrResult> qrResults = qrReader.Read(qrInput);
// Assuming you have the QR results in qrResults as before
foreach (var result in qrResults)
{
Console.WriteLine(result.Value); // Print the QR code content to the console
}Imports IronQr
Imports IronSoftware.Drawing
Imports System
Imports System.Collections.Generic
IronQr.License.LicenseKey = "License-Key"
' Load the image file that contains the QR Code
Dim inputImage = AnyBitmap.FromFile("QRCode.png")
' Prepare the image for QR code detection
Dim qrInput As New QrImageInput(inputImage)
' Initialize the QR Code reader
Dim qrReader As New QrReader()
' Execute QR Code reading on the provided image
Dim qrResults As IEnumerable(Of QrResult) = qrReader.Read(qrInput)
' Assuming you have the QR results in qrResults as before
For Each result In qrResults
Console.WriteLine(result.Value) ' Print the QR code content to the console
Next resultImports IronQr
Imports IronSoftware.Drawing
Imports System
Imports System.Collections.Generic
IronQr.License.LicenseKey = "License-Key"
' Load the image file that contains the QR Code
Dim inputImage = AnyBitmap.FromFile("QRCode.png")
' Prepare the image for QR code detection
Dim qrInput As New QrImageInput(inputImage)
' Initialize the QR Code reader
Dim qrReader As New QrReader()
' Execute QR Code reading on the provided image
Dim qrResults As IEnumerable(Of QrResult) = qrReader.Read(qrInput)
' Assuming you have the QR results in qrResults as before
For Each result In qrResults
Console.WriteLine(result.Value) ' Print the QR code content to the console
Next resultSüreç, gerekli IronQr ve IronSoftware.Drawing ad alanlarının eklenmesiyle başlar. Görüntü düzenlemeleri için IronSoftware.Drawing ad alanındaki Color türü ayrıca belirtilir.
QR kodu okuma işlemine başlamadan önce lisans anahtarınızı IronQr.License.LicenseKey özelliğine atayarak yazılımı etkinleştirmeniz gerekir. Ardından kod, AnyBitmap.FromFile("QRCode.png") kullanarak QR kodu görüntüsünü dosyadan yükler.
Görüntü yüklendikten sonra QR kodu tespiti için hazırlanır. Bunun için görüntüyü tutan bir QrImageInput nesnesi oluşturulur.
Bu özelliğin temelinde, QR kodu okuma işlemi için bir örneği oluşturulan QrReader sınıfı yer alır. Okuyucu, hazırlanan görüntüyü analiz ederek içerdiği QR kodlarını arar. İşlemin sonucu, her biri görüntüde tespit edilen bir QR kodunu temsil eden QrResult nesnelerinden oluşan bir koleksiyondur.
QR kodlarına kodlanmış verilere erişmek ve bunları kullanmak için, kod bir foreach döngüsü kullanarak sonuç koleksiyonu üzerinden döner. Her QrResult nesnesi, erişilebilen ve görüntülenebilen QR kodunun değeri gibi özellikler içerir.
Özel QR Okuma Modu Seçenekleri
IronQR, farklı ihtiyaçlara uyum sağlayan çeşitli QR kodu okuma modları sunar.
- Karışık Tarama Modu: Hız ve doğruluk arasında denge kurar, net olmayan veya kısmen gizlenmiş QR kodları için kullanışlıdır.
- Makine Öğrenimi (ML) Tarama Modu: Hasar görmüş veya okunması zor QR kodlarını okumak için gelişmiş teknoloji kullanır, tespiti zor senaryolar için idealdir.
- Temel Tarama Modu: Net ve basit QR kodları için en kolay ve en hızlı yöntemdir.
using IronQr;
using IronQr.Enum;
using IronSoftware.Drawing;
using System.Collections.Generic;
IronQr.License.LicenseKey = "License-Key";
// Load the image file that contains the QR Code
var inputImage = AnyBitmap.FromFile("QRCode.png");
QrImageInput mixedScanInput = new QrImageInput(inputImage, QrScanMode.OnlyDetectionModel);
IEnumerable<QrResult> mixedScanResults = new QrReader().Read(mixedScanInput);
QrImageInput mlScanInput = new QrImageInput(inputImage, QrScanMode.OnlyDetectionModel);
IEnumerable<QrResult> mlScanResults = new QrReader().Read(mlScanInput);
QrImageInput basicScanInput = new QrImageInput(inputImage, QrScanMode.OnlyBasicScan);
IEnumerable<QrResult> basicScanResults = new QrReader().Read(basicScanInput);using IronQr;
using IronQr.Enum;
using IronSoftware.Drawing;
using System.Collections.Generic;
IronQr.License.LicenseKey = "License-Key";
// Load the image file that contains the QR Code
var inputImage = AnyBitmap.FromFile("QRCode.png");
QrImageInput mixedScanInput = new QrImageInput(inputImage, QrScanMode.OnlyDetectionModel);
IEnumerable<QrResult> mixedScanResults = new QrReader().Read(mixedScanInput);
QrImageInput mlScanInput = new QrImageInput(inputImage, QrScanMode.OnlyDetectionModel);
IEnumerable<QrResult> mlScanResults = new QrReader().Read(mlScanInput);
QrImageInput basicScanInput = new QrImageInput(inputImage, QrScanMode.OnlyBasicScan);
IEnumerable<QrResult> basicScanResults = new QrReader().Read(basicScanInput);Imports IronQr
Imports IronQr.Enum
Imports IronSoftware.Drawing
Imports System.Collections.Generic
IronQr.License.LicenseKey = "License-Key"
' Load the image file that contains the QR Code
Dim inputImage = AnyBitmap.FromFile("QRCode.png")
Dim mixedScanInput As New QrImageInput(inputImage, QrScanMode.OnlyDetectionModel)
Dim mixedScanResults As IEnumerable(Of QrResult) = (New QrReader()).Read(mixedScanInput)
Dim mlScanInput As New QrImageInput(inputImage, QrScanMode.OnlyDetectionModel)
Dim mlScanResults As IEnumerable(Of QrResult) = (New QrReader()).Read(mlScanInput)
Dim basicScanInput As New QrImageInput(inputImage, QrScanMode.OnlyBasicScan)
Dim basicScanResults As IEnumerable(Of QrResult) = (New QrReader()).Read(basicScanInput)Imports IronQr
Imports IronQr.Enum
Imports IronSoftware.Drawing
Imports System.Collections.Generic
IronQr.License.LicenseKey = "License-Key"
' Load the image file that contains the QR Code
Dim inputImage = AnyBitmap.FromFile("QRCode.png")
Dim mixedScanInput As New QrImageInput(inputImage, QrScanMode.OnlyDetectionModel)
Dim mixedScanResults As IEnumerable(Of QrResult) = (New QrReader()).Read(mixedScanInput)
Dim mlScanInput As New QrImageInput(inputImage, QrScanMode.OnlyDetectionModel)
Dim mlScanResults As IEnumerable(Of QrResult) = (New QrReader()).Read(mlScanInput)
Dim basicScanInput As New QrImageInput(inputImage, QrScanMode.OnlyBasicScan)
Dim basicScanResults As IEnumerable(Of QrResult) = (New QrReader()).Read(basicScanInput)Gelişmiş QR Kodlarını Okuyun
IronQR'nin gelişmiş QR kodu okuma yetenekleri, QR kodlarını tarama ve çözümleme konusunda kapsamlı bir yaklaşım sunar. Bu özellikler, temel okumanın ötesine geçerek daha ayrıntılı etkileşim ve veri çıkarma olanağı sağlar.
using IronQr;
using IronSoftware.Drawing;
using System;
using System.Collections.Generic;
IronQr.License.LicenseKey = "License-Key";
var imageToScan = AnyBitmap.FromFile("QRCode.png");
QrImageInput qrInput = new QrImageInput(imageToScan);
QrReader qrScanner = new QrReader();
IEnumerable<QrResult> scanResults = qrScanner.Read(qrInput);
foreach (QrResult qrResult in scanResults)
{
Console.WriteLine(qrResult.Value);
Console.WriteLine(qrResult.Url);
foreach (IronSoftware.Drawing.PointF coordinate in qrResult.Points)
{
Console.WriteLine($"{coordinate.X}, {coordinate.Y}");
}
}using IronQr;
using IronSoftware.Drawing;
using System;
using System.Collections.Generic;
IronQr.License.LicenseKey = "License-Key";
var imageToScan = AnyBitmap.FromFile("QRCode.png");
QrImageInput qrInput = new QrImageInput(imageToScan);
QrReader qrScanner = new QrReader();
IEnumerable<QrResult> scanResults = qrScanner.Read(qrInput);
foreach (QrResult qrResult in scanResults)
{
Console.WriteLine(qrResult.Value);
Console.WriteLine(qrResult.Url);
foreach (IronSoftware.Drawing.PointF coordinate in qrResult.Points)
{
Console.WriteLine($"{coordinate.X}, {coordinate.Y}");
}
}Imports IronQr
Imports IronSoftware.Drawing
Imports System
Imports System.Collections.Generic
IronQr.License.LicenseKey = "License-Key"
Dim imageToScan = AnyBitmap.FromFile("QRCode.png")
Dim qrInput As New QrImageInput(imageToScan)
Dim qrScanner As New QrReader()
Dim scanResults As IEnumerable(Of QrResult) = qrScanner.Read(qrInput)
For Each qrResult As QrResult In scanResults
Console.WriteLine(qrResult.Value)
Console.WriteLine(qrResult.Url)
For Each coordinate As IronSoftware.Drawing.PointF In qrResult.Points
Console.WriteLine($"{coordinate.X}, {coordinate.Y}")
Next coordinate
Next qrResultImports IronQr
Imports IronSoftware.Drawing
Imports System
Imports System.Collections.Generic
IronQr.License.LicenseKey = "License-Key"
Dim imageToScan = AnyBitmap.FromFile("QRCode.png")
Dim qrInput As New QrImageInput(imageToScan)
Dim qrScanner As New QrReader()
Dim scanResults As IEnumerable(Of QrResult) = qrScanner.Read(qrInput)
For Each qrResult As QrResult In scanResults
Console.WriteLine(qrResult.Value)
Console.WriteLine(qrResult.Url)
For Each coordinate As IronSoftware.Drawing.PointF In qrResult.Points
Console.WriteLine($"{coordinate.X}, {coordinate.Y}")
Next coordinate
Next qrResultC# uygulamasında IronQR kütüphanesi kullanarak bir QR Kod üreteci oluşturmak için bu adımları dikkatlice takip edin. Bu kılavuz, bir Windows formu uygulaması kurulumunu, IronQR kütüphanesinin yüklenmesini, bir QR kodu oluşturmak için kod yazmayı ve çıktıyı anlamayı gösterecektir.
Adım 1: Visual Studio'da Bir Windows Uygulaması Oluşturun
-
Bilgisayarınızda Visual Studio'yu başlatın.
-
"Yeni Bir Proje Oluştur" düğmesine tıklayın.
-
Proje türü olarak Windows Forms Uygulaması seçin. Dil olarak C# seçtiğinizden emin olun.

-
Projeniz için bir ad girin ve kaydedilecek yeri seçin. Sonraki ekranda .NET framework seçin. Sonra Oluştur üzerine tıklayın.

Adım 2: IronQR Kütüphanesini Yükleyin
Şimdi projeye IronQR kütüphanesini yükleme zamanı. IronQR kütüphanesini farklı yöntemlerle yükleyebilirsiniz.
NuGet Paket Yöneticisini Kullanarak Yükleme
-
Çözüm Gezgini'nde projenize sağ tıklayın ve NuGet Paketlerini Yönet seçeneğini seçin.
-
Arama kutusuna
IronQRyazın ve Enter tuşuna basın.
-
Listeden IronQR'yi bulun ve yanındaki Yükle düğmesine tıklayın.

NuGet Paket Yöneticisi Konsolu Kullanarak Yükleme
- Araçlar > NuGet Paket Yöneticisi > Paket Yöneticisi Konsolu sekmesine gidin.

Install-Package IronQryazın ve Enter tuşuna basın.

Adım 3: Arayüzü Tasarlayın

3.1 Üst Başlık

QR Kod Üretici uygulamasını başlattıklarında, kullanıcılar hemen 'QR Generator IronQR' başlıklı etkileyici bir başlıkla karşılaşırlar, bu başlık kalın ve otoriter bir yazı tipinde ayarlanmıştır.
3.2 Giriş Bölümü
QR Kodu için Metin Girişi
Kullanıcılar QR kodlarına kodlamak istedikleri veriyi girebilir. QR kodu oluşturucu uygulamasını başlatan kullanıcıları, kalın ve güçlü bir yazı tipiyle yazılmış, dikkat çekici "QR Generator IronQR" başlığı karşılar.
Logo Seçimi

"Logo Seç" alanı ek bir özelleştirme katmanı sağlar. Kullanıcılar, QR koduna gömülecek bir logoyu yükleyebilir.
Renk Yapılandırması

Renk seçimi için kullanılan butonlar, kullanıcıların QR kodlarının renk paletini özelleştirmelerini sağlar.
3.3 Stil Parametreleri

Boyut Ayarları
Kullanıcıların QR kodunun genel boyutunu belirtmelerine olanak tanır.
Kenar Boşluğu Ayarları
Kullanıcıların QR kodunun çevresindeki beyaz boşluğu belirlemelerine olanak tanır.
3.4 Çıktı Önizleme
Oluşturulan QR kodunun gerçek zamanlı bir ön izlemesini sağlar.

3.5 Eylem Düğmeleri
QR Kodu Oluştur
QR kodu oluşturma sürecini tetikler.

QR Kodunu Kaydet
QR kodunu kaydetmek için bir kaydetme iletişim kutusunu açar.

Formu Sıfırla
Tüm önceki girişleri ve seçimleri temizler.

Adım 4: Arka Uç Mantığını Yazın
4.1 Kurulum ve Başlatma
Gerekli ad alanlarını içerir: IronQr ve IronSoftware.Drawing.
using IronQr;
using IronSoftware.Drawing;
using Color = IronSoftware.Drawing.Color;using IronQr;
using IronSoftware.Drawing;
using Color = IronSoftware.Drawing.Color;Imports IronQr
Imports IronSoftware.Drawing
Imports Color = IronSoftware.Drawing.ColorImports IronQr
Imports IronSoftware.Drawing
Imports Color = IronSoftware.Drawing.Colorpublic QR_Generator()
{
InitializeComponent();
SetLicenseKey();
EnsureDirectoryExists(qrCodesDirectory);
}public QR_Generator()
{
InitializeComponent();
SetLicenseKey();
EnsureDirectoryExists(qrCodesDirectory);
}'INSTANT VB WARNING: The following constructor is declared outside of its associated class:
'ORIGINAL LINE: public QR_Generator()
Public Sub New()
InitializeComponent()
SetLicenseKey()
EnsureDirectoryExists(qrCodesDirectory)
End Sub'INSTANT VB WARNING: The following constructor is declared outside of its associated class:
'ORIGINAL LINE: public QR_Generator()
Public Sub New()
InitializeComponent()
SetLicenseKey()
EnsureDirectoryExists(qrCodesDirectory)
End Sub4.2 Lisans Anahtarı Yapılandırması
IronQR kütüphanesi için geçerli bir lisans anahtarını uygular:
private static void SetLicenseKey() {
IronQr.License.LicenseKey = "YOUR_LICENSE_KEY";
}private static void SetLicenseKey() {
IronQr.License.LicenseKey = "YOUR_LICENSE_KEY";
}Private Shared Sub SetLicenseKey()
IronQr.License.LicenseKey = "YOUR_LICENSE_KEY"
End SubPrivate Shared Sub SetLicenseKey()
IronQr.License.LicenseKey = "YOUR_LICENSE_KEY"
End Sub"YOUR_LICENSE_KEY" yerine gerçek lisans anahtarınızı girin.
4.3 Dizin Yönetimi
Gerekli dizinleri kontrol eder veya oluşturur.
private static void EnsureDirectoryExists(string path)
{
if (!System.IO.Directory.Exists(path))
{
System.IO.Directory.CreateDirectory(path);
}
}private static void EnsureDirectoryExists(string path)
{
if (!System.IO.Directory.Exists(path))
{
System.IO.Directory.CreateDirectory(path);
}
}Private Shared Sub EnsureDirectoryExists(ByVal path As String)
If Not System.IO.Directory.Exists(path) Then
System.IO.Directory.CreateDirectory(path)
End If
End SubPrivate Shared Sub EnsureDirectoryExists(ByVal path As String)
If Not System.IO.Directory.Exists(path) Then
System.IO.Directory.CreateDirectory(path)
End If
End SubQR kodları dizininin yolu, uygulamanın başlangıç yolunu "QR Codes" klasör adıyla birleştiren qrCodesDirectory olarak QR_Generator sınıfı yapıcısında tanımlanır:
string qrCodesDirectory = System.IO.Path.Combine(Application.StartupPath, "QR Codes");string qrCodesDirectory = System.IO.Path.Combine(Application.StartupPath, "QR Codes");Dim qrCodesDirectory As String = System.IO.Path.Combine(Application.StartupPath, "QR Codes")Dim qrCodesDirectory As String = System.IO.Path.Combine(Application.StartupPath, "QR Codes")4.4 Renk Seçimi
Renk diyaloğu bileşenleri ve yardımcı fonksiyonlar sağlar.
private string ColorToHex(System.Drawing.Color color)
{
return $"#{color.R:X2}{color.G:X2}{color.B:X2}";
}private string ColorToHex(System.Drawing.Color color)
{
return $"#{color.R:X2}{color.G:X2}{color.B:X2}";
}Private Function ColorToHex(ByVal color As System.Drawing.Color) As String
Return $"#{color.R:X2}{color.G:X2}{color.B:X2}"
End FunctionPrivate Function ColorToHex(ByVal color As System.Drawing.Color) As String
Return $"#{color.R:X2}{color.G:X2}{color.B:X2}"
End FunctionUpdateColor metodu, seçilen rengi onaltılık dize kullanarak IronSoftware.Drawing.Color formatına dönüştürür ve seçime bağlı olarak QR kodunun ön plan veya arka plan rengini günceller. Ayrıca yeni renk seçimini yansıtmak için kullanıcı arayüzünü günceller:
private void UpdateColor(ref Color targetColor, Control display, bool isBackground)
{
if (select_color.ShowDialog() == DialogResult.OK)
{
var hexColor = ColorToHex(select_color.Color);
targetColor = new Color(hexColor);
display.BackColor = select_color.Color;
}
}private void UpdateColor(ref Color targetColor, Control display, bool isBackground)
{
if (select_color.ShowDialog() == DialogResult.OK)
{
var hexColor = ColorToHex(select_color.Color);
targetColor = new Color(hexColor);
display.BackColor = select_color.Color;
}
}Private Sub UpdateColor(ByRef targetColor As Color, ByVal display As Control, ByVal isBackground As Boolean)
If select_color.ShowDialog() = DialogResult.OK Then
Dim hexColor = ColorToHex(select_color.Color)
targetColor = New Color(hexColor)
display.BackColor = select_color.Color
End If
End SubPrivate Sub UpdateColor(ByRef targetColor As Color, ByVal display As Control, ByVal isBackground As Boolean)
If select_color.ShowDialog() = DialogResult.OK Then
Dim hexColor = ColorToHex(select_color.Color)
targetColor = New Color(hexColor)
display.BackColor = select_color.Color
End If
End Sub4.5 Logo Ekleme
Kullanıcının bir logo seçmesine imkan tanır.
private void btn_logo_Click(object sender, EventArgs e)
{
if (select_logo.ShowDialog() == DialogResult.OK)
{
try
{
logoBmp = new AnyBitmap(select_logo.FileName);
selected_logo.Image = Image.FromFile(select_logo.FileName);
}
catch (Exception ex)
{
ShowError("An error occurred while loading the logo", ex.Message);
}
}
}private void btn_logo_Click(object sender, EventArgs e)
{
if (select_logo.ShowDialog() == DialogResult.OK)
{
try
{
logoBmp = new AnyBitmap(select_logo.FileName);
selected_logo.Image = Image.FromFile(select_logo.FileName);
}
catch (Exception ex)
{
ShowError("An error occurred while loading the logo", ex.Message);
}
}
}Private Sub btn_logo_Click(ByVal sender As Object, ByVal e As EventArgs)
If select_logo.ShowDialog() = DialogResult.OK Then
Try
logoBmp = New AnyBitmap(select_logo.FileName)
selected_logo.Image = Image.FromFile(select_logo.FileName)
Catch ex As Exception
ShowError("An error occurred while loading the logo", ex.Message)
End Try
End If
End SubPrivate Sub btn_logo_Click(ByVal sender As Object, ByVal e As EventArgs)
If select_logo.ShowDialog() = DialogResult.OK Then
Try
logoBmp = New AnyBitmap(select_logo.FileName)
selected_logo.Image = Image.FromFile(select_logo.FileName)
Catch ex As Exception
ShowError("An error occurred while loading the logo", ex.Message)
End Try
End If
End Sub4.6 QR Kodu Oluşturma
Kullanıcı girdilerine dayanarak QR kodları oluşturma mantığını içerir.
private void btn_generate_Click(object sender, EventArgs e)
{
GenerateQRCode();
}private void btn_generate_Click(object sender, EventArgs e)
{
GenerateQRCode();
}Private Sub btn_generate_Click(ByVal sender As Object, ByVal e As EventArgs)
GenerateQRCode()
End SubPrivate Sub btn_generate_Click(ByVal sender As Object, ByVal e As EventArgs)
GenerateQRCode()
End SubQrOptions nesnesi, QR kodunun hasara veya kısmen kapanmaya karşı dayanıklılığını artıran hata düzeltme seviyesini tanımlar. CreateStyleOptions metodu, renkler, boyutlar ve logo gibi kullanıcının özelleştirdiği ayarları içeren bir QrStyleOptions nesnesi oluşturur. Metodun ayrıntıları şöyledir:
private QrStyleOptions CreateStyleOptions()
{
return new QrStyleOptions
{
BackgroundColor = bgColor,
Color = color,
Dimensions = txt_dimension.Value > 0 ? Convert.ToInt32(txt_dimension.Value) : throw new ArgumentException("Please select valid dimensions!"),
Margins = Convert.ToInt32(txt_margin.Value),
Logo = logoBmp != null ? new QrLogo { Bitmap = logoBmp, Width = 50, Height = 50, CornerRadius = 5 } : null
};
}private QrStyleOptions CreateStyleOptions()
{
return new QrStyleOptions
{
BackgroundColor = bgColor,
Color = color,
Dimensions = txt_dimension.Value > 0 ? Convert.ToInt32(txt_dimension.Value) : throw new ArgumentException("Please select valid dimensions!"),
Margins = Convert.ToInt32(txt_margin.Value),
Logo = logoBmp != null ? new QrLogo { Bitmap = logoBmp, Width = 50, Height = 50, CornerRadius = 5 } : null
};
}Private Function CreateStyleOptions() As QrStyleOptions
'INSTANT VB TODO TASK: Throw expressions are not converted by Instant VB:
'ORIGINAL LINE: return new QrStyleOptions { BackgroundColor = bgColor, Color = color, Dimensions = txt_dimension.Value > 0 ? Convert.ToInt32(txt_dimension.Value) : throw new ArgumentException("Please select valid dimensions!"), Margins = Convert.ToInt32(txt_margin.Value), Logo = logoBmp != null ? new QrLogo { Bitmap = logoBmp, Width = 50, Height = 50, CornerRadius = 5 } : null };
Return New QrStyleOptions With {
.BackgroundColor = bgColor,
.Color = color,
.Dimensions = If(txt_dimension.Value > 0, Convert.ToInt32(txt_dimension.Value), throw New ArgumentException("Please select valid dimensions!")),
.Margins = Convert.ToInt32(txt_margin.Value),
.Logo = If(logoBmp IsNot Nothing, New QrLogo With {
.Bitmap = logoBmp,
.Width = 50,
.Height = 50,
.CornerRadius = 5
}, Nothing)
}
End FunctionPrivate Function CreateStyleOptions() As QrStyleOptions
'INSTANT VB TODO TASK: Throw expressions are not converted by Instant VB:
'ORIGINAL LINE: return new QrStyleOptions { BackgroundColor = bgColor, Color = color, Dimensions = txt_dimension.Value > 0 ? Convert.ToInt32(txt_dimension.Value) : throw new ArgumentException("Please select valid dimensions!"), Margins = Convert.ToInt32(txt_margin.Value), Logo = logoBmp != null ? new QrLogo { Bitmap = logoBmp, Width = 50, Height = 50, CornerRadius = 5 } : null };
Return New QrStyleOptions With {
.BackgroundColor = bgColor,
.Color = color,
.Dimensions = If(txt_dimension.Value > 0, Convert.ToInt32(txt_dimension.Value), throw New ArgumentException("Please select valid dimensions!")),
.Margins = Convert.ToInt32(txt_margin.Value),
.Logo = If(logoBmp IsNot Nothing, New QrLogo With {
.Bitmap = logoBmp,
.Width = 50,
.Height = 50,
.CornerRadius = 5
}, Nothing)
}
End Function4.7 QR Kodunu Kaydetme
Oluşturulan QR kodunun kaydedilmesini yönetir.
private void btn_save_Click(object sender, EventArgs e)
{
SaveQRCode();
}
private void SaveQRCode()
{
if (pictureBox.Image == null)
{
MessageBox.Show("There is no QR code to save.", "Error");
return;
}
saveFileDialog.Filter = "PNG Files|*.png|JPEG Files|*.jpg";
saveFileDialog.Title = "Save QR Code";
saveFileDialog.FileName = "QRCode";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
pictureBox.Image.Save(saveFileDialog.FileName, DetermineImageFormat(saveFileDialog.FileName));
MessageBox.Show("QR Code has been saved!", "Success");
}
catch (Exception ex)
{
ShowError("An error occurred while saving the QR code", ex.Message);
}
}
}private void btn_save_Click(object sender, EventArgs e)
{
SaveQRCode();
}
private void SaveQRCode()
{
if (pictureBox.Image == null)
{
MessageBox.Show("There is no QR code to save.", "Error");
return;
}
saveFileDialog.Filter = "PNG Files|*.png|JPEG Files|*.jpg";
saveFileDialog.Title = "Save QR Code";
saveFileDialog.FileName = "QRCode";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
pictureBox.Image.Save(saveFileDialog.FileName, DetermineImageFormat(saveFileDialog.FileName));
MessageBox.Show("QR Code has been saved!", "Success");
}
catch (Exception ex)
{
ShowError("An error occurred while saving the QR code", ex.Message);
}
}
}Private Sub btn_save_Click(ByVal sender As Object, ByVal e As EventArgs)
SaveQRCode()
End Sub
Private Sub SaveQRCode()
If pictureBox.Image Is Nothing Then
MessageBox.Show("There is no QR code to save.", "Error")
Return
End If
saveFileDialog.Filter = "PNG Files|*.png|JPEG Files|*.jpg"
saveFileDialog.Title = "Save QR Code"
saveFileDialog.FileName = "QRCode"
If saveFileDialog.ShowDialog() = DialogResult.OK Then
Try
pictureBox.Image.Save(saveFileDialog.FileName, DetermineImageFormat(saveFileDialog.FileName))
MessageBox.Show("QR Code has been saved!", "Success")
Catch ex As Exception
ShowError("An error occurred while saving the QR code", ex.Message)
End Try
End If
End SubPrivate Sub btn_save_Click(ByVal sender As Object, ByVal e As EventArgs)
SaveQRCode()
End Sub
Private Sub SaveQRCode()
If pictureBox.Image Is Nothing Then
MessageBox.Show("There is no QR code to save.", "Error")
Return
End If
saveFileDialog.Filter = "PNG Files|*.png|JPEG Files|*.jpg"
saveFileDialog.Title = "Save QR Code"
saveFileDialog.FileName = "QRCode"
If saveFileDialog.ShowDialog() = DialogResult.OK Then
Try
pictureBox.Image.Save(saveFileDialog.FileName, DetermineImageFormat(saveFileDialog.FileName))
MessageBox.Show("QR Code has been saved!", "Success")
Catch ex As Exception
ShowError("An error occurred while saving the QR code", ex.Message)
End Try
End If
End Subprivate System.Drawing.Imaging.ImageFormat DetermineImageFormat(string filePath)
{
return System.IO.Path.GetExtension(filePath).ToLower() == ".jpg" ? System.Drawing.Imaging.ImageFormat.Jpeg : System.Drawing.Imaging.ImageFormat.Png;
}private System.Drawing.Imaging.ImageFormat DetermineImageFormat(string filePath)
{
return System.IO.Path.GetExtension(filePath).ToLower() == ".jpg" ? System.Drawing.Imaging.ImageFormat.Jpeg : System.Drawing.Imaging.ImageFormat.Png;
}Private Function DetermineImageFormat(ByVal filePath As String) As System.Drawing.Imaging.ImageFormat
Return If(System.IO.Path.GetExtension(filePath).ToLower() = ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg, System.Drawing.Imaging.ImageFormat.Png)
End FunctionPrivate Function DetermineImageFormat(ByVal filePath As String) As System.Drawing.Imaging.ImageFormat
Return If(System.IO.Path.GetExtension(filePath).ToLower() = ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg, System.Drawing.Imaging.ImageFormat.Png)
End Function4.8 Uygulamayı Sıfırlama
Kullanıcı girdilerini temizler ve form durumunu sıfırlar.
private void btn_reset_Click(object sender, EventArgs e)
{
ResetFields();
}
private void ResetFields()
{
txt_QR.Text = string.Empty;
txt_dimension.Value = 200;
txt_margin.Value = 0;
bgColor = Color.White;
color = Color.Black;
txt_selected_color.BackColor = System.Drawing.Color.White;
txt_selected_bgcolor.BackColor = System.Drawing.Color.Black;
logoBmp = null;
selected_logo.Image = null;
pictureBox.Image = null;
}private void btn_reset_Click(object sender, EventArgs e)
{
ResetFields();
}
private void ResetFields()
{
txt_QR.Text = string.Empty;
txt_dimension.Value = 200;
txt_margin.Value = 0;
bgColor = Color.White;
color = Color.Black;
txt_selected_color.BackColor = System.Drawing.Color.White;
txt_selected_bgcolor.BackColor = System.Drawing.Color.Black;
logoBmp = null;
selected_logo.Image = null;
pictureBox.Image = null;
}Private Sub btn_reset_Click(ByVal sender As Object, ByVal e As EventArgs)
ResetFields()
End Sub
Private Sub ResetFields()
txt_QR.Text = String.Empty
txt_dimension.Value = 200
txt_margin.Value = 0
bgColor = Color.White
color = Color.Black
txt_selected_color.BackColor = System.Drawing.Color.White
txt_selected_bgcolor.BackColor = System.Drawing.Color.Black
logoBmp = Nothing
selected_logo.Image = Nothing
pictureBox.Image = Nothing
End SubPrivate Sub btn_reset_Click(ByVal sender As Object, ByVal e As EventArgs)
ResetFields()
End Sub
Private Sub ResetFields()
txt_QR.Text = String.Empty
txt_dimension.Value = 200
txt_margin.Value = 0
bgColor = Color.White
color = Color.Black
txt_selected_color.BackColor = System.Drawing.Color.White
txt_selected_bgcolor.BackColor = System.Drawing.Color.Black
logoBmp = Nothing
selected_logo.Image = Nothing
pictureBox.Image = Nothing
End Sub4.9 Hata Yönetimi
Kullanıcılara hata mesajlarını gösterir.
private static void ShowError(string title, string message)
{
MessageBox.Show($"{title}: {message}", "Error");
}private static void ShowError(string title, string message)
{
MessageBox.Show($"{title}: {message}", "Error");
}Private Shared Sub ShowError(ByVal title As String, ByVal message As String)
MessageBox.Show($"{title}: {message}", "Error")
End SubPrivate Shared Sub ShowError(ByVal title As String, ByVal message As String)
MessageBox.Show($"{title}: {message}", "Error")
End Sub4.10 Tam Kod Örneği
Yukarıdaki tüm özellikleri bir arada gösteren tam kod, projenizle bağlantılı örnek dosyada bulunabilir.
using IronQr;
using IronSoftware.Drawing;
using Color = IronSoftware.Drawing.Color;
namespace IronQR_QR_Generator_WinForms
{
public partial class QR_Generator : Form
{
string qrCodesDirectory = System.IO.Path.Combine(Application.StartupPath, "QR Codes");
Color bgColor = Color.White;
Color color = Color.Black;
AnyBitmap? logoBmp = null;
public QR_Generator()
{
InitializeComponent();
SetLicenseKey();
EnsureDirectoryExists(qrCodesDirectory);
}
private static void SetLicenseKey()
{
IronQr.License.LicenseKey = "License-Key";
}
private static void EnsureDirectoryExists(string path)
{
if (!System.IO.Directory.Exists(path))
{
System.IO.Directory.CreateDirectory(path);
}
}
private void btn_color_Click(object sender, EventArgs e)
{
UpdateColor(ref color, txt_selected_color, false);
}
private void btn_background_Click(object sender, EventArgs e)
{
UpdateColor(ref bgColor, txt_selected_bgcolor, true);
}
private string ColorToHex(System.Drawing.Color color)
{
return $"#{color.R:X2}{color.G:X2}{color.B:X2}";
}
private void UpdateColor(ref Color targetColor, Control display, bool isBackground)
{
if (select_color.ShowDialog() == DialogResult.OK)
{
var hexColor = ColorToHex(select_color.Color);
targetColor = new Color(hexColor);
display.BackColor = select_color.Color;
}
}
private void btn_logo_Click(object sender, EventArgs e)
{
if (select_logo.ShowDialog() == DialogResult.OK)
{
try
{
logoBmp = new AnyBitmap(select_logo.FileName);
selected_logo.Image = Image.FromFile(select_logo.FileName);
}
catch (Exception ex)
{
ShowError("An error occurred while loading the logo", ex.Message);
}
}
}
private void btn_generate_Click(object sender, EventArgs e)
{
GenerateQRCode();
}
private void GenerateQRCode()
{
try
{
var options = new QrOptions(QrErrorCorrectionLevel.High);
var myQr = QrWriter.Write(txt_QR.Text, options);
var style = CreateStyleOptions();
var qrImage = myQr.Save(style);
var fileName = $"{DateTime.Now:yyyyMMddHHmmssfff}_QR.png";
var fullPath = System.IO.Path.Combine(qrCodesDirectory, fileName);
qrImage.SaveAs(fullPath);
pictureBox.Image = Image.FromFile(fullPath);
}
catch (Exception ex)
{
ShowError("An error occurred during QR code generation or saving", ex.Message);
}
}
private QrStyleOptions CreateStyleOptions()
{
return new QrStyleOptions
{
BackgroundColor = bgColor,
Color = color,
Dimensions = txt_dimension.Value > 0 ? Convert.ToInt32(txt_dimension.Value) : throw new ArgumentException("Please select valid dimensions!"),
Margins = Convert.ToInt32(txt_margin.Value),
Logo = logoBmp != null ? new QrLogo { Bitmap = logoBmp, Width = 50, Height = 50, CornerRadius = 5 } : null
};
}
private void btn_save_Click(object sender, EventArgs e)
{
SaveQRCode();
}
private void SaveQRCode()
{
if (pictureBox.Image == null)
{
MessageBox.Show("There is no QR code to save.", "Error");
return;
}
saveFileDialog.Filter = "PNG Files|*.png|JPEG Files|*.jpg";
saveFileDialog.Title = "Save QR Code";
saveFileDialog.FileName = "QRCode";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
pictureBox.Image.Save(saveFileDialog.FileName, DetermineImageFormat(saveFileDialog.FileName));
MessageBox.Show("QR Code has been saved!", "Success");
}
catch (Exception ex)
{
ShowError("An error occurred while saving the QR code", ex.Message);
}
}
}
private System.Drawing.Imaging.ImageFormat DetermineImageFormat(string filePath)
{
return System.IO.Path.GetExtension(filePath).ToLower() == ".jpg" ? System.Drawing.Imaging.ImageFormat.Jpeg : System.Drawing.Imaging.ImageFormat.Png;
}
private void btn_reset_Click(object sender, EventArgs e)
{
ResetFields();
}
private void ResetFields()
{
txt_QR.Text = string.Empty;
txt_dimension.Value = 200;
txt_margin.Value = 0;
bgColor = Color.White;
color = Color.Black;
txt_selected_color.BackColor = bgColor;
txt_selected_bgcolor.BackColor = color;
logoBmp = null;
selected_logo.Image = null;
pictureBox.Image = null;
}
private static void ShowError(string title, string message)
{
MessageBox.Show($"{title}: {message}", "Error");
}
}
}using IronQr;
using IronSoftware.Drawing;
using Color = IronSoftware.Drawing.Color;
namespace IronQR_QR_Generator_WinForms
{
public partial class QR_Generator : Form
{
string qrCodesDirectory = System.IO.Path.Combine(Application.StartupPath, "QR Codes");
Color bgColor = Color.White;
Color color = Color.Black;
AnyBitmap? logoBmp = null;
public QR_Generator()
{
InitializeComponent();
SetLicenseKey();
EnsureDirectoryExists(qrCodesDirectory);
}
private static void SetLicenseKey()
{
IronQr.License.LicenseKey = "License-Key";
}
private static void EnsureDirectoryExists(string path)
{
if (!System.IO.Directory.Exists(path))
{
System.IO.Directory.CreateDirectory(path);
}
}
private void btn_color_Click(object sender, EventArgs e)
{
UpdateColor(ref color, txt_selected_color, false);
}
private void btn_background_Click(object sender, EventArgs e)
{
UpdateColor(ref bgColor, txt_selected_bgcolor, true);
}
private string ColorToHex(System.Drawing.Color color)
{
return $"#{color.R:X2}{color.G:X2}{color.B:X2}";
}
private void UpdateColor(ref Color targetColor, Control display, bool isBackground)
{
if (select_color.ShowDialog() == DialogResult.OK)
{
var hexColor = ColorToHex(select_color.Color);
targetColor = new Color(hexColor);
display.BackColor = select_color.Color;
}
}
private void btn_logo_Click(object sender, EventArgs e)
{
if (select_logo.ShowDialog() == DialogResult.OK)
{
try
{
logoBmp = new AnyBitmap(select_logo.FileName);
selected_logo.Image = Image.FromFile(select_logo.FileName);
}
catch (Exception ex)
{
ShowError("An error occurred while loading the logo", ex.Message);
}
}
}
private void btn_generate_Click(object sender, EventArgs e)
{
GenerateQRCode();
}
private void GenerateQRCode()
{
try
{
var options = new QrOptions(QrErrorCorrectionLevel.High);
var myQr = QrWriter.Write(txt_QR.Text, options);
var style = CreateStyleOptions();
var qrImage = myQr.Save(style);
var fileName = $"{DateTime.Now:yyyyMMddHHmmssfff}_QR.png";
var fullPath = System.IO.Path.Combine(qrCodesDirectory, fileName);
qrImage.SaveAs(fullPath);
pictureBox.Image = Image.FromFile(fullPath);
}
catch (Exception ex)
{
ShowError("An error occurred during QR code generation or saving", ex.Message);
}
}
private QrStyleOptions CreateStyleOptions()
{
return new QrStyleOptions
{
BackgroundColor = bgColor,
Color = color,
Dimensions = txt_dimension.Value > 0 ? Convert.ToInt32(txt_dimension.Value) : throw new ArgumentException("Please select valid dimensions!"),
Margins = Convert.ToInt32(txt_margin.Value),
Logo = logoBmp != null ? new QrLogo { Bitmap = logoBmp, Width = 50, Height = 50, CornerRadius = 5 } : null
};
}
private void btn_save_Click(object sender, EventArgs e)
{
SaveQRCode();
}
private void SaveQRCode()
{
if (pictureBox.Image == null)
{
MessageBox.Show("There is no QR code to save.", "Error");
return;
}
saveFileDialog.Filter = "PNG Files|*.png|JPEG Files|*.jpg";
saveFileDialog.Title = "Save QR Code";
saveFileDialog.FileName = "QRCode";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
pictureBox.Image.Save(saveFileDialog.FileName, DetermineImageFormat(saveFileDialog.FileName));
MessageBox.Show("QR Code has been saved!", "Success");
}
catch (Exception ex)
{
ShowError("An error occurred while saving the QR code", ex.Message);
}
}
}
private System.Drawing.Imaging.ImageFormat DetermineImageFormat(string filePath)
{
return System.IO.Path.GetExtension(filePath).ToLower() == ".jpg" ? System.Drawing.Imaging.ImageFormat.Jpeg : System.Drawing.Imaging.ImageFormat.Png;
}
private void btn_reset_Click(object sender, EventArgs e)
{
ResetFields();
}
private void ResetFields()
{
txt_QR.Text = string.Empty;
txt_dimension.Value = 200;
txt_margin.Value = 0;
bgColor = Color.White;
color = Color.Black;
txt_selected_color.BackColor = bgColor;
txt_selected_bgcolor.BackColor = color;
logoBmp = null;
selected_logo.Image = null;
pictureBox.Image = null;
}
private static void ShowError(string title, string message)
{
MessageBox.Show($"{title}: {message}", "Error");
}
}
}Imports IronQr
Imports IronSoftware.Drawing
Imports Color = IronSoftware.Drawing.Color
Namespace IronQR_QR_Generator_WinForms
Partial Public Class QR_Generator
Inherits Form
Private qrCodesDirectory As String = System.IO.Path.Combine(Application.StartupPath, "QR Codes")
Private bgColor As Color = Color.White
Private color As Color = Color.Black
Private logoBmp? As AnyBitmap = Nothing
Public Sub New()
InitializeComponent()
SetLicenseKey()
EnsureDirectoryExists(qrCodesDirectory)
End Sub
Private Shared Sub SetLicenseKey()
IronQr.License.LicenseKey = "License-Key"
End Sub
Private Shared Sub EnsureDirectoryExists(ByVal path As String)
If Not System.IO.Directory.Exists(path) Then
System.IO.Directory.CreateDirectory(path)
End If
End Sub
Private Sub btn_color_Click(ByVal sender As Object, ByVal e As EventArgs)
UpdateColor(color, txt_selected_color, False)
End Sub
Private Sub btn_background_Click(ByVal sender As Object, ByVal e As EventArgs)
UpdateColor(bgColor, txt_selected_bgcolor, True)
End Sub
Private Function ColorToHex(ByVal color As System.Drawing.Color) As String
Return $"#{color.R:X2}{color.G:X2}{color.B:X2}"
End Function
Private Sub UpdateColor(ByRef targetColor As Color, ByVal display As Control, ByVal isBackground As Boolean)
If select_color.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Dim hexColor = ColorToHex(select_color.Color)
targetColor = New Color(hexColor)
display.BackColor = select_color.Color
End If
End Sub
Private Sub btn_logo_Click(ByVal sender As Object, ByVal e As EventArgs)
If select_logo.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
logoBmp = New AnyBitmap(select_logo.FileName)
selected_logo.Image = Image.FromFile(select_logo.FileName)
Catch ex As Exception
ShowError("An error occurred while loading the logo", ex.Message)
End Try
End If
End Sub
Private Sub btn_generate_Click(ByVal sender As Object, ByVal e As EventArgs)
GenerateQRCode()
End Sub
Private Sub GenerateQRCode()
Try
Dim options = New QrOptions(QrErrorCorrectionLevel.High)
Dim myQr = QrWriter.Write(txt_QR.Text, options)
Dim style = CreateStyleOptions()
Dim qrImage = myQr.Save(style)
Dim fileName = $"{DateTime.Now:yyyyMMddHHmmssfff}_QR.png"
Dim fullPath = System.IO.Path.Combine(qrCodesDirectory, fileName)
qrImage.SaveAs(fullPath)
pictureBox.Image = Image.FromFile(fullPath)
Catch ex As Exception
ShowError("An error occurred during QR code generation or saving", ex.Message)
End Try
End Sub
Private Function CreateStyleOptions() As QrStyleOptions
'INSTANT VB TODO TASK: Throw expressions are not converted by Instant VB:
'ORIGINAL LINE: return new QrStyleOptions { BackgroundColor = bgColor, Color = color, Dimensions = txt_dimension.Value > 0 ? Convert.ToInt32(txt_dimension.Value) : throw new ArgumentException("Please select valid dimensions!"), Margins = Convert.ToInt32(txt_margin.Value), Logo = logoBmp != null ? new QrLogo { Bitmap = logoBmp, Width = 50, Height = 50, CornerRadius = 5 } : null };
Return New QrStyleOptions With {
.BackgroundColor = bgColor,
.Color = color,
.Dimensions = If(txt_dimension.Value > 0, Convert.ToInt32(txt_dimension.Value), throw New ArgumentException("Please select valid dimensions!")),
.Margins = Convert.ToInt32(txt_margin.Value),
.Logo = If(logoBmp IsNot Nothing, New QrLogo With {
.Bitmap = logoBmp,
.Width = 50,
.Height = 50,
.CornerRadius = 5
}, Nothing)
}
End Function
Private Sub btn_save_Click(ByVal sender As Object, ByVal e As EventArgs)
SaveQRCode()
End Sub
Private Sub SaveQRCode()
If pictureBox.Image Is Nothing Then
MessageBox.Show("There is no QR code to save.", "Error")
Return
End If
saveFileDialog.Filter = "PNG Files|*.png|JPEG Files|*.jpg"
saveFileDialog.Title = "Save QR Code"
saveFileDialog.FileName = "QRCode"
If saveFileDialog.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
pictureBox.Image.Save(saveFileDialog.FileName, DetermineImageFormat(saveFileDialog.FileName))
MessageBox.Show("QR Code has been saved!", "Success")
Catch ex As Exception
ShowError("An error occurred while saving the QR code", ex.Message)
End Try
End If
End Sub
Private Function DetermineImageFormat(ByVal filePath As String) As System.Drawing.Imaging.ImageFormat
Return If(System.IO.Path.GetExtension(filePath).ToLower() = ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg, System.Drawing.Imaging.ImageFormat.Png)
End Function
Private Sub btn_reset_Click(ByVal sender As Object, ByVal e As EventArgs)
ResetFields()
End Sub
Private Sub ResetFields()
txt_QR.Text = String.Empty
txt_dimension.Value = 200
txt_margin.Value = 0
bgColor = Color.White
color = Color.Black
txt_selected_color.BackColor = bgColor
txt_selected_bgcolor.BackColor = color
logoBmp = Nothing
selected_logo.Image = Nothing
pictureBox.Image = Nothing
End Sub
Private Shared Sub ShowError(ByVal title As String, ByVal message As String)
MessageBox.Show($"{title}: {message}", "Error")
End Sub
End Class
End NamespaceImports IronQr
Imports IronSoftware.Drawing
Imports Color = IronSoftware.Drawing.Color
Namespace IronQR_QR_Generator_WinForms
Partial Public Class QR_Generator
Inherits Form
Private qrCodesDirectory As String = System.IO.Path.Combine(Application.StartupPath, "QR Codes")
Private bgColor As Color = Color.White
Private color As Color = Color.Black
Private logoBmp? As AnyBitmap = Nothing
Public Sub New()
InitializeComponent()
SetLicenseKey()
EnsureDirectoryExists(qrCodesDirectory)
End Sub
Private Shared Sub SetLicenseKey()
IronQr.License.LicenseKey = "License-Key"
End Sub
Private Shared Sub EnsureDirectoryExists(ByVal path As String)
If Not System.IO.Directory.Exists(path) Then
System.IO.Directory.CreateDirectory(path)
End If
End Sub
Private Sub btn_color_Click(ByVal sender As Object, ByVal e As EventArgs)
UpdateColor(color, txt_selected_color, False)
End Sub
Private Sub btn_background_Click(ByVal sender As Object, ByVal e As EventArgs)
UpdateColor(bgColor, txt_selected_bgcolor, True)
End Sub
Private Function ColorToHex(ByVal color As System.Drawing.Color) As String
Return $"#{color.R:X2}{color.G:X2}{color.B:X2}"
End Function
Private Sub UpdateColor(ByRef targetColor As Color, ByVal display As Control, ByVal isBackground As Boolean)
If select_color.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Dim hexColor = ColorToHex(select_color.Color)
targetColor = New Color(hexColor)
display.BackColor = select_color.Color
End If
End Sub
Private Sub btn_logo_Click(ByVal sender As Object, ByVal e As EventArgs)
If select_logo.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
logoBmp = New AnyBitmap(select_logo.FileName)
selected_logo.Image = Image.FromFile(select_logo.FileName)
Catch ex As Exception
ShowError("An error occurred while loading the logo", ex.Message)
End Try
End If
End Sub
Private Sub btn_generate_Click(ByVal sender As Object, ByVal e As EventArgs)
GenerateQRCode()
End Sub
Private Sub GenerateQRCode()
Try
Dim options = New QrOptions(QrErrorCorrectionLevel.High)
Dim myQr = QrWriter.Write(txt_QR.Text, options)
Dim style = CreateStyleOptions()
Dim qrImage = myQr.Save(style)
Dim fileName = $"{DateTime.Now:yyyyMMddHHmmssfff}_QR.png"
Dim fullPath = System.IO.Path.Combine(qrCodesDirectory, fileName)
qrImage.SaveAs(fullPath)
pictureBox.Image = Image.FromFile(fullPath)
Catch ex As Exception
ShowError("An error occurred during QR code generation or saving", ex.Message)
End Try
End Sub
Private Function CreateStyleOptions() As QrStyleOptions
'INSTANT VB TODO TASK: Throw expressions are not converted by Instant VB:
'ORIGINAL LINE: return new QrStyleOptions { BackgroundColor = bgColor, Color = color, Dimensions = txt_dimension.Value > 0 ? Convert.ToInt32(txt_dimension.Value) : throw new ArgumentException("Please select valid dimensions!"), Margins = Convert.ToInt32(txt_margin.Value), Logo = logoBmp != null ? new QrLogo { Bitmap = logoBmp, Width = 50, Height = 50, CornerRadius = 5 } : null };
Return New QrStyleOptions With {
.BackgroundColor = bgColor,
.Color = color,
.Dimensions = If(txt_dimension.Value > 0, Convert.ToInt32(txt_dimension.Value), throw New ArgumentException("Please select valid dimensions!")),
.Margins = Convert.ToInt32(txt_margin.Value),
.Logo = If(logoBmp IsNot Nothing, New QrLogo With {
.Bitmap = logoBmp,
.Width = 50,
.Height = 50,
.CornerRadius = 5
}, Nothing)
}
End Function
Private Sub btn_save_Click(ByVal sender As Object, ByVal e As EventArgs)
SaveQRCode()
End Sub
Private Sub SaveQRCode()
If pictureBox.Image Is Nothing Then
MessageBox.Show("There is no QR code to save.", "Error")
Return
End If
saveFileDialog.Filter = "PNG Files|*.png|JPEG Files|*.jpg"
saveFileDialog.Title = "Save QR Code"
saveFileDialog.FileName = "QRCode"
If saveFileDialog.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
pictureBox.Image.Save(saveFileDialog.FileName, DetermineImageFormat(saveFileDialog.FileName))
MessageBox.Show("QR Code has been saved!", "Success")
Catch ex As Exception
ShowError("An error occurred while saving the QR code", ex.Message)
End Try
End If
End Sub
Private Function DetermineImageFormat(ByVal filePath As String) As System.Drawing.Imaging.ImageFormat
Return If(System.IO.Path.GetExtension(filePath).ToLower() = ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg, System.Drawing.Imaging.ImageFormat.Png)
End Function
Private Sub btn_reset_Click(ByVal sender As Object, ByVal e As EventArgs)
ResetFields()
End Sub
Private Sub ResetFields()
txt_QR.Text = String.Empty
txt_dimension.Value = 200
txt_margin.Value = 0
bgColor = Color.White
color = Color.Black
txt_selected_color.BackColor = bgColor
txt_selected_bgcolor.BackColor = color
logoBmp = Nothing
selected_logo.Image = Nothing
pictureBox.Image = Nothing
End Sub
Private Shared Sub ShowError(ByVal title As String, ByVal message As String)
MessageBox.Show($"{title}: {message}", "Error")
End Sub
End Class
End NamespaceAdım 5: Uygulamayı Çalıştırın
Uygulama çalıştırıldığında, ana pencere girdiler, stil, çıkış ve eylemler için bölümlerle düzenlenmiş olarak görünür. Kullanıcı arayüzünü takip ederek veri girin, QR kodunuzu özelleştirin ve istediğiniz gibi QR kodunu oluşturup kaydedin.
Sonuç
Bu kılavuzda, bir C# uygulamasında IronQR kütüphanesini kullanarak QR kodları oluşturma sürecini ele aldık. Visual Studio projesini kurma, IronQR kütüphanesini entegre etme, kullanıcı dostu bir arayüz tasarlama ve arka uç mantığını yazma adımlarını açıklayarak uygulamalarınıza QR kodu işlevi eklemenin ne kadar kolay olduğunu gösterdik.
IronQR'nin yeteneklerini daha fazla keşfetmek isteyenler için, başlangıçta yararlanabileceğiniz IronQR sunar. IronQR'yi projelerinize entegre etmeye karar verirseniz, lisanslar $999'dan başlar ve profesyonel düzeyde QR kodu oluşturma için uygun maliyetli bir çözüm sunar.
Sıkça Sorulan Sorular
IronQR nedir?
IronQR, Iron Software'ın .NET QR Kod kütüphanesidir. .NET uygulamalarına QR kod işlevselliği entegre eder, çeşitli .NET sürümlerini destekler ve QR kod okuma, oluşturma ve özelleştirme gibi özellikler sunar.
C# projemde IronQR nasıl kurarım?
NuGet Paket Yöneticisi üzerinden 'IronQR' arayarak ve Yükle'ye tıklayarak veya NuGet Paket Yöneticisi Konsolu üzerinden 'Install-Package IronQR' komutunu girerek IronQR kurabilirsiniz.
IronQR kullanarak C# ile QR kodu üretici oluşturma adımları nelerdir?
QR kodu üretici oluşturmak için, Visual Studio'da bir Windows Forms Uygulaması oluşturarak başlayın, IronQR'yi yükleyin, arayüzü tasarlayın, QR kodu üretim mantığını yazın ve sonunda uygulamanızı çalıştırarak QR kodları üretin.
IronQR ile oluşturulan QR kodlarını özelleştirebilir miyim?
Evet, IronQR, ölçüler, kenar boşlukları, renkler gibi parametreleri ayarlayarak ve kişiselleştirilmiş QR kod tasarımı için logolar ekleyerek QR kodlarını özelleştirmenize olanak tanır.
IronQR'de lisans anahtarının rolü nedir?
IronQR kütüphanesi özelliklerini etkinleştirmek için bir lisans anahtarı gereklidir. QR kodu oluşturma ve okuma işlemlerinin tam işlevselliğini sağlamak için lisans anahtarını uygulama kodunuza ekleyin.
IronQR'de hangi farklı tarama modları mevcuttur?
IronQR, hız, doğruluk dengesini sağlamak ve hasarlı veya okunması zor kodlar dahil olmak üzere çeşitli QR kod koşullarını ele almak için Karışık Tarama Modu, Makine Öğrenimi Tarama Modu ve Temel Tarama Modu sunar.
IronQR, QR kod okuma işlemini nasıl gerçekleştirir?
IronQR, resim yükleyerek, tespit için hazırlayarak ve gömülü verileri etkin bir şekilde analiz edip çıkarmak için bir QrReader kullanarak QR kodlarını okumak için kolay bir yol sağlar.
IronQR farklı geliştirme ortamları ile uyumlu mu?
Evet, IronQR geniş bir .NET proje türünü destekler ve Windows, Linux, macOS, iOS ve Android gibi çeşitli ortamlarla uyumludur.
IronQR kullanırken hataları nasıl ele almak önerilir?
QR kodu oluşturma veya okuma sırasında meydana gelebilecek istisnaları yakalamak ve sorunsuz bir deneyim sağlamak için uygulamanızda hata yönetimi uygulamanız önerilir.
QR kodu üretici uygulamasını farklı platformlarda çalıştırabilir miyim?
Evet, IronQR'nin çeşitli .NET frameworkleri ile uyumu sayesinde, QR kodu üretici uygulamasını Windows, Linux ve macOS gibi birden fazla platformda çalıştırabilirsiniz.
Curtis Chau, Bilgisayar Bilimleri alanında Lisans Derecesine (Carleton Üniversitesi) sahip ve Node.js, TypeScript, JavaScript ve React konularında uzmanlaşmış ön uç geliştirmeyle ilgileniyor. Sezgisel ve estetik açıdan hoş kullanıcı arayüzleri oluşturma tutkunu, Curtis modern çerçevelerle çalışmayı ve iyi yapılandırılmış, görsel olarak çekici kılavuzlar oluşturmayı seviyor.