# C# QR Kod Üretici Application
<div class="alert alert-info iron-variant-1" role="alert">
<a href="/csharp/qr/">IronQR</a>, Iron Software'in yeni .NET QR Kod kütüphanesidir. Herhangi bir açıdan %99,99 doğrulukla QR kodlarını okumak için en son makine öğrenimi tekniklerinden yararlanın. Yeni QR kodlarını kolaylıkla oluşturun ve özelleştirin! <a href="/csharp/qr/tutorials/csharp-qr-code-generator/">IronQR ile Başlayın</a> şimdi!
</div>
C# kullanarak [QR kodları](https://en.wikipedia.org/wiki/QR_code) oluşturma rehberimize hoş geldiniz! QR kodları ve .NET barkod DLL, 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 düzgün bir yolunu arıyor olun, bu kodlar son derece kullanışlı olabilir. Bu kılavuzda, [IronQR](/csharp/qr/) kullanarak QR kodlarının nasıl verimli bir şekilde oluşturulacağını göstereceğiz, böylece ihtiyaçlarınıza uygun QR kodları oluşturabilirsiniz. Bu kütüphane, C# ile çalışan herkes için karmaşık mantıklara girmeden QR kodları oluşturmayı kolaylaştırır. Her şeye başlangıç için ihtiyaç duyduğunuz şeyleri sağlayarak sizi adım adım yönlendireceğiz. Bu işlevselliği uygulamanıza eklemek için mi, yoksa sadece nasıl yapıldığını mı merak ediyorsunuz, doğru yerdesiniz. Hadi başlayalım.
<div class="hsg-featured-snippet">
<h2>C#'ta QR Kod Üretici Nasıl Oluşturulur</h2>
<ol>
<li>Visual Studio'da bir Windows Forms Uygulaması Oluşturun</li>
<li><a class="js-modal-open" data-modal-id="trial-license-after-download" href="https://www.nuget.org/packages/IronQR/">NuGet'i kullanarak QR Kütüphanesi yükleyin</a></li>
<li>Formun ön yüz elementlerini tasarlayın</li>
<li>QR üretimi mantığını yazın</li>
<li>Uygulamayı çalıştırın ve QR kodlarını oluşturmaya başlayın</li>
</ol>
</div>
## Install QR Kod Üretici Library in C#
!!!--LIBRARY_START_TRIAL_BLOCK--!!!
-----------
Başlamadan önce, `IronQR` NuGet Paketini yüklememiz gerekiyor.
```shell
:ProductInstall
```
## IronQR: C# QR Kütüphanesi
[IronQR](/csharp/qr/), .NET uygulamalarına QR kodu işlevselliği 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 kodu okuma](/csharp/qr/examples/read-qr-code/) ve [QR kodu oluşturma](/csharp/qr/examples/generate-qr-code/) yetenekleri, birden fazla resim formatı için destek ve QR kodlarına boyutlandırma, stil ve logolar ekleme gibi özelleştirme seçenekleri dahil olmak üzere gelişmiş özelliklerle ayrılır.
## IronQR'nin Bazı Ana Özellikleri
IronQR, temel QR kodu oluşturmanın ötesinde işlevselliğini genişleterek geniş bir QR koduyla ilgili görevi karşılamak için tasarlanmış bir dizi özellik sunar. Bu özellikleri inceleyelim ve örnek kodlarını inceleyelim, böylece bunları herhangi bir .NET uygulama şablonuna, örneğin konsol uygulamasına entegre edebileceksiniz.
### QR Kodları Oku
IronQR, QR kodlarını çözme konusunda üstünlük sağlar ve kullanıcılar için QR kodları içindeki bilgilere kolay bir şekilde erişim sağlar. Basit URL'lerden karmaşık gömülü bilgilere kadar QR kodlarından veri çıkartabilir.
```cs
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
}
```
Süreç, gerekli ad alanlarının dahil edilmesiyle başlar: `IronQr` ve `IronSoftware.Drawing`. `Color` ad alanından @@@@ ile özel bir şekilde belirtilerek görüntü manipülasyonlarını ele alır.
QR kod okuma işlemine dalmadan önce, yazılımı lisans anahtarınızla `IronQr.License.LicenseKey`'ya atayarak etkinleştirmeniz önemlidir. Kod daha sonra bir dosyadan QR kod görüntüsünü `AnyBitmap.FromFile("QRCode.png")` kullanarak yüklemeye devam eder.
Resim yüklendiğinde, QR kodu tespiti için hazırlama adımı gelir. Bu hazırlık, görüntü için bir kap görevi gören `QrImageInput` nesnesi oluşturarak yapılır.
Bu özelliğin özü, QR kod okuma işlemini gerçekleştirmek için örneklenen ve kullanılan `QrReader` sınıfında yatar. Hesap okuma işlemi, hazırlanmış görüntüyü analiz eder ve içerdiği QR kodlarını arar. Bu işlemin sonucu, her biri görüntüde tespit edilen bir QR kodunu temsil eden `QrResult` nesne koleksiyonudur.
QR kodlarında kodlanan verilere erişmek ve onları kullanmak için, kod bir `foreach` döngüsü kullanarak sonuçlar koleksiyonu arasından yineleme yapar. Her `QrResult` nesnesi, erişilebilen ve gösterilebilen QR kodunun değeri gibi özellikler içerir.
### Özel QR Okuma Modu Seçenekleri
IronQR, çeşitli ihtiyaçlar için çok yönlü bir hale getiren farklı modlar sağlar.
- **Karma Tarama Modu**: Hız ve doğruluk arasında denge kurar, net olmayan veya kısmen gizlenmiş QR kodları için yararlıdır.
- **Makine Öğrenimi (ML) Tarama Modu**: Hasar görmüş veya okunması zor QR kodlarını okumak için gelişmiş teknoloji kullanır, tespit edilmesi zor senaryolar için idealdir.
- **Temel Tarama Modu**: En basit ve en hızlı yol, net ve basit QR kodları için.
```cs
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);
```
### Gelişmiş QR Kodları Oku
IronQR'nin gelişmiş QR kodu okuma yetenekleri, QR kodu tarama ve çözme konusunda kapsamlı bir yaklaşım sunar. Bu özellik seti, temel okuyup okumanın ötesine geçer, daha derin bir etkileşim ve veri çıkarma sağlama imkanı sunar.
```cs
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}");
}
}
```
C# 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
1. Bilgisayarınızda Visual Studio'yu başlatın.
2. "Yeni Bir Proje Oluştur" düğmesine tıklayın.
3. Proje türü olarak **Windows Forms Uygulaması** seçin. Dil olarak C# seçtiğinizden emin olun.

4. 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
1. Çözüm Gezgini'nde projenize sağ tıklayın ve **NuGet Paketlerini Yönet** seçeneğini seçin.
2. Arama kutusuna `IronQR` yazın ve **Enter**'a basın.

3. Listeden **IronQR**'yi bulun ve yanındaki **Yükle** düğmesine tıklayın.

### NuGet Paket Yöneticisi Konsolu Kullanarak Yükleme
1. **Araçlar > NuGet Paket Yöneticisi > Paket Yöneticisi Konsolu** sekmesine gidin.
<div class="content-img-align-center">
<img src="/static-assets/qr/tutorials/csharp-qr-code-generator-application/nuget-package-manager.webp" alt="NuGet Paket Yöneticisi" class="img-responsive add-shadow img-margin" />
</div>
2. `Install-Package IronQr` yazın ve Enter'a basın.
<div class="content-img-align-center">
<img src="/static-assets/qr/tutorials/csharp-qr-code-generator-application/install-ironqr-via-pm.webp" alt="IronQR Yükle" class="img-responsive add-shadow img-margin" />
</div>
## Adım 3: Arayüz Tasarla
<div class="content-img-align-center">
<img src="/static-assets/qr/tutorials/csharp-qr-code-generator-application/qr-code-generator.webp" alt="QR Kod Üretici" class="img-responsive add-shadow img-margin" />
</div>
### 3.1 Başlık Başlığı
<div class="content-img-align-center">
<img src="/static-assets/qr/tutorials/csharp-qr-code-generator-application/generate-qr-code.webp" alt="QR Kodunu Oluştur" class="img-responsive add-shadow img-margin" />
</div>
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 Kod için Metin Girişi
Kullanıcılar QR kodlarına kodlamak istedikleri veriyi girebilir.
#### Logo Seçimi
<div class="content-img-align-center">
<img src="/static-assets/qr/tutorials/csharp-qr-code-generator-application/select-logo.webp" alt="Logo Seç" class="img-responsive add-shadow img-margin" />
</div>
"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ı
<div class="content-img-align-center">
<img src="/static-assets/qr/tutorials/csharp-qr-code-generator-application/background-color.webp" alt="Arka Plan Rengi" class="img-responsive add-shadow img-margin" />
</div>
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
<div class="content-img-align-center">
<img src="/static-assets/qr/tutorials/csharp-qr-code-generator-application/styling.webp" alt="Stil" class="img-responsive add-shadow img-margin" />
</div>
#### Boyut Ayarları
Kullanıcıların QR kodunun genel boyutunu belirtmelerine olanak tanır.
#### Margin 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.
<div class="content-img-align-center">
<img src="/static-assets/qr/tutorials/csharp-qr-code-generator-application/qr-output.webp" alt="QR Çıkışı" class="img-responsive add-shadow img-margin" />
</div>
### 3.5 Eylem Düğmeleri
#### QR Üret
QR kodu oluşturma sürecini tetikler.
<div class="content-img-align-center">
<img src="/static-assets/qr/tutorials/csharp-qr-code-generator-application/qr-code-in-csharp.webp" alt="C#'ta QR Kodu" class="img-responsive add-shadow img-margin" />
</div>
#### QR Kod Kaydet
QR kodunu kaydetmek için bir kaydetme diyaloğunu açar.
<div class="content-img-align-center">
<img src="/static-assets/qr/tutorials/csharp-qr-code-generator-application/save.webp" alt="Kaydet" class="img-responsive add-shadow img-margin" />
</div>
#### Formu Sıfırla
Tüm önceki girişleri ve seçimleri temizler.
<div class="content-img-align-center">
<img src="/static-assets/qr/tutorials/csharp-qr-code-generator-application/reset.webp" alt="Sıfırla" class="img-responsive add-shadow img-margin" />
</div>
## 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`.
```cs
using IronQr;
using IronSoftware.Drawing;
using Color = IronSoftware.Drawing.Color;
```
```cs
public QR_Generator()
{
InitializeComponent();
SetLicenseKey();
EnsureDirectoryExists(qrCodesDirectory);
}
```
### 4.2 Lisans Anahtarı Yapılandırması
IronQR kütüphanesi için geçerli bir lisans anahtarını uygular:
```csharp
private static void SetLicenseKey() {
IronQr.License.LicenseKey = "YOUR_LICENSE_KEY";
}
```
`"YOUR_LICENSE_KEY"` ifadesini gerçek lisans anahtarınızla değiştirin.
### 4.3 Dizin Yönetimi
Gerekli dizinleri kontrol eder veya oluşturur.
```cs
private static void EnsureDirectoryExists(string path)
{
if (!System.IO.Directory.Exists(path))
{
System.IO.Directory.CreateDirectory(path);
}
}
```
QR kodları dizinine giden yol, uygulamanın başlangıç yolunu bir 'QR Kodlar' klasör adıyla birleştiren `qrCodesDirectory` olarak `QR_Generator` sınıfı yapıcısında tanımlanıyor.
```cs
string qrCodesDirectory = System.IO.Path.Combine(Application.StartupPath, "QR Codes");
```
### 4.4 Renk Seçimi
Renk diyaloğu bileşenleri ve yardımcı fonksiyonlar sağlar.
```cs
private string ColorToHex(System.Drawing.Color color)
{
return $"#{color.R:X2}{color.G:X2}{color.B:X2}";
}
```
`UpdateColor` metodu, seçilen rengi alır ve onaltılık dize kullanarak `IronSoftware.Drawing.Color` formatına dönüştürür ve seçimlere bağlı olarak QR kodunun ön veya arka plan rengini günceller. Ayrıca kullanıcı arayüzü, yeni renk tercihinin yansıtılması için güncellenir:
```cs
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;
}
}
```
### 4.5 Logo Ekleme
Kullanıcının bir logo seçmesine imkan tanır.
```cs
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);
}
}
}
```
### 4.6 QR Kod Üretimi
Kullanıcı girdilerine dayanarak QR kodları oluşturma mantığını içerir.
```cs
private void btn_generate_Click(object sender, EventArgs e)
{
GenerateQRCode();
}
```
`QrOptions` nesnesi, QR kodunun hasara veya gizlenmeye karşı dayanıklılığını artıran hata düzeltme seviyesini tanımlar. `CreateStyleOptions` metodu, renkler, boyutlar ve logo gibi kullanıcının özel ayarlarını içeren bir `QrStyleOptions` nesnesi üretir. İşte yöntem detayları:
```cs
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
};
}
```
### 4.7 QR Kodunu Kaydetme
Oluşturulan QR kodunun kaydedilmesini yönetir.
```cs
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);
}
}
}
```
```cs
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;
}
```
### 4.8 Uygulamayı Sıfırlama
Kullanıcı girdilerini temizler ve form durumunu sıfırlar.
```cs
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;
}
```
### 4.9 Hata Yönetimi
Kullanıcılara hata mesajlarını gösterir.
```cs
private static void ShowError(string title, string message)
{
MessageBox.Show($"{title}: {message}", "Error");
}
```
### 4.10 Tam Kod Örneği
Yukarıdaki tüm özellikleri bir arada gösteren tam kod, projenizle bağlantılı örnek dosyada bulunabilir.
```cs
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");
}
}
}
```
## Adı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ç
Sonuç olarak, bu kılavuz, C# uygulamasında IronQR kütüphanesini kullanarak QR kodları oluşturma sürecinde size rehberlik etti. Projenizi Visual Studio'da kurmaktan, IronQR kütüphanesini entegre etmeye, kullanıcı dostu bir arayüz tasarlamaktan ve arka uç mantığını yazmaya kadar adımları bölerek, uygulamalarınıza QR kodu işlevi eklemenin ne kadar erişilebilir olduğunu gösterdik.
IronQR'nin yeteneklerini daha fazla keşfetmekle ilgilenenler için, IronQR'nin başlamanıza yardımcı olacak bir <a class="js-modal-open" data-modal-id="trial-license">ücretsiz deneme</a> sunduğunu belirtmekte fayda var. IronQR'yi projelerinize entegre etme kararı verirseniz, lisanslar `$liteLicense`'dan başlar ve profesyonel düzeyde QR kod üretimi için uygun maliyetli bir çözüm sunar.
IronQR, Iron Software'in yeni .NET QR Kod kütüphanesidir. Herhangi bir açıdan %99,99 doğrulukla QR kodlarını okumak için en son makine öğrenimi tekniklerinden yararlanın. Yeni QR kodlarını kolaylıkla oluşturun ve özelleştirin! IronQR ile Başlayın şimdi!
C# kullanarak QR kodları oluşturma rehberimize hoş geldiniz! QR kodları ve .NET barkod DLL, 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 düzgün bir yolunu arıyor olun, bu kodlar son derece kullanışlı olabilir. Bu kılavuzda, IronQR kullanarak QR kodlarının nasıl verimli bir şekilde oluşturulacağını göstereceğiz, böylece ihtiyaçlarınıza uygun QR kodları oluşturabilirsiniz. Bu kütüphane, C# ile çalışan herkes için karmaşık mantıklara girmeden QR kodları oluşturmayı kolaylaştırır. Her şeye başlangıç için ihtiyaç duyduğunuz şeyleri sağlayarak sizi adım adım yönlendireceğiz. Bu işlevselliği uygulamanıza eklemek için mi, yoksa sadece nasıl yapıldığını mı merak ediyorsunuz, doğru yerdesiniz. Hadi başlayalım.
C#'ta QR Kod Üretici Nasıl Oluşturulur
Visual Studio'da bir Windows Forms Uygulaması Oluşturun
Uygulamayı çalıştırın ve QR kodlarını oluşturmaya başlayın
Install QR Kod Üretici Library in C#
Start using IronQR in your project today with a free trial.
İlk Adım:
Başlamadan önce, IronQR NuGet Paketini yüklememiz gerekiyor.
PM > Install-Package IronQR
Install-Package IronQR
IronQR: C# QR Kütüphanesi
IronQR, .NET uygulamalarına QR kodu işlevselliği 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 kodu okuma ve QR kodu oluşturma yetenekleri, birden fazla resim formatı için destek ve QR kodlarına boyutlandırma, stil ve logolar ekleme gibi özelleştirme seçenekleri dahil olmak üzere gelişmiş özelliklerle ayrılır.
IronQR'nin Bazı Ana Özellikleri
IronQR, temel QR kodu oluşturmanın ötesinde işlevselliğini genişleterek geniş bir QR koduyla ilgili görevi karşılamak için tasarlanmış bir dizi özellik sunar. Bu özellikleri inceleyelim ve örnek kodlarını inceleyelim, böylece bunları herhangi bir .NET uygulama şablonuna, örneğin konsol uygulamasına entegre edebileceksiniz.
QR Kodları Oku
IronQR, QR kodlarını çözme konusunda üstünlük sağlar ve kullanıcılar için QR kodları içindeki bilgilere kolay bir şekilde erişim sağlar. Basit URL'lerden karmaşık gömülü bilgilere kadar QR kodlarından veri çıkartabilir.
using IronQr;using IronSoftware.Drawing;using System;using System.Collections.Generic;IronQr.License.LicenseKey = "License-Key";// Load the image file that contains the QR Codevar inputImage = AnyBitmap.FromFile("QRCode.png");// Prepare the image for QR code detectionQrImageInput qrInput = new QrImageInput(inputImage);// Initialize the QR Code readerQrReader qrReader = new QrReader();// Execute QR Code reading on the provided imageIEnumerable<QrResult> qrResults = qrReader.Read(qrInput);// Assuming you have the QR results in qrResults as beforeforeach (var result in qrResults){Console.WriteLine(result.Value); // Print the QR code content to the console}
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
}
ImportsIronQrImportsIronSoftware.DrawingImportsSystemImportsSystem.Collections.GenericIronQr.License.LicenseKey = "License-Key"' Load the image file that contains the QR CodeDim inputImage = AnyBitmap.FromFile("QRCode.png")' Prepare the image for QR code detectionDim qrInput As New QrImageInput(inputImage)' Initialize the QR Code readerDim qrReader As New QrReader()' Execute QR Code reading on the provided imageDim qrResults AsIEnumerable(OfQrResult) = qrReader.Read(qrInput)' Assuming you have the QR results in qrResults as beforeFor Each result In qrResultsConsole.WriteLine(result.Value) ' Print the QR code content to the consoleNext result
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 result
Süreç, gerekli ad alanlarının dahil edilmesiyle başlar: IronQr ve IronSoftware.Drawing. Color ad alanından @@@@ ile özel bir şekilde belirtilerek görüntü manipülasyonlarını ele alır.
QR kod okuma işlemine dalmadan önce, yazılımı lisans anahtarınızla IronQr.License.LicenseKey'ya atayarak etkinleştirmeniz önemlidir. Kod daha sonra bir dosyadan QR kod görüntüsünü AnyBitmap.FromFile("QRCode.png") kullanarak yüklemeye devam eder.
Resim yüklendiğinde, QR kodu tespiti için hazırlama adımı gelir. Bu hazırlık, görüntü için bir kap görevi gören QrImageInput nesnesi oluşturarak yapılır.
Bu özelliğin özü, QR kod okuma işlemini gerçekleştirmek için örneklenen ve kullanılan QrReader sınıfında yatar. Hesap okuma işlemi, hazırlanmış görüntüyü analiz eder ve içerdiği QR kodlarını arar. Bu işlemin sonucu, her biri görüntüde tespit edilen bir QR kodunu temsil eden QrResult nesne koleksiyonudur.
QR kodlarında kodlanan verilere erişmek ve onları kullanmak için, kod bir foreach döngüsü kullanarak sonuçlar koleksiyonu arasından yineleme yapar. Her QrResult nesnesi, erişilebilen ve gösterilebilen QR kodunun değeri gibi özellikler içerir.
Özel QR Okuma Modu Seçenekleri
IronQR, çeşitli ihtiyaçlar için çok yönlü bir hale getiren farklı modlar sağlar.
Karma Tarama Modu: Hız ve doğruluk arasında denge kurar, net olmayan veya kısmen gizlenmiş QR kodları için yararlıdır.
Makine Öğrenimi (ML) Tarama Modu: Hasar görmüş veya okunması zor QR kodlarını okumak için gelişmiş teknoloji kullanır, tespit edilmesi zor senaryolar için idealdir.
Temel Tarama Modu: En basit ve en hızlı yol, net ve basit QR kodları için.
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 Codevar 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);
ImportsIronQrImportsIronQr.EnumImportsIronSoftware.DrawingImportsSystem.Collections.GenericIronQr.License.LicenseKey = "License-Key"' Load the image file that contains the QR CodeDim inputImage = AnyBitmap.FromFile("QRCode.png")Dim mixedScanInput As New QrImageInput(inputImage, QrScanMode.OnlyDetectionModel)Dim mixedScanResults AsIEnumerable(OfQrResult) = (New QrReader()).Read(mixedScanInput)Dim mlScanInput As New QrImageInput(inputImage, QrScanMode.OnlyDetectionModel)Dim mlScanResults AsIEnumerable(OfQrResult) = (New QrReader()).Read(mlScanInput)Dim basicScanInput As New QrImageInput(inputImage, QrScanMode.OnlyBasicScan)Dim basicScanResults AsIEnumerable(OfQrResult) = (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ı Oku
IronQR'nin gelişmiş QR kodu okuma yetenekleri, QR kodu tarama ve çözme konusunda kapsamlı bir yaklaşım sunar. Bu özellik seti, temel okuyup okumanın ötesine geçer, daha derin bir etkileşim ve veri çıkarma sağlama imkanı sunar.
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}");
}
}
ImportsIronQrImportsIronSoftware.DrawingImportsSystemImportsSystem.Collections.GenericIronQr.License.LicenseKey = "License-Key"Dim imageToScan = AnyBitmap.FromFile("QRCode.png")Dim qrInput As New QrImageInput(imageToScan)Dim qrScanner As New QrReader()Dim scanResults AsIEnumerable(OfQrResult) = qrScanner.Read(qrInput)For Each qrResult AsQrResultIn scanResultsConsole.WriteLine(qrResult.Value)Console.WriteLine(qrResult.Url) For Each coordinate AsIronSoftware.Drawing.PointFIn qrResult.PointsConsole.WriteLine($"{coordinate.X}, {coordinate.Y}") Next coordinateNext qrResult
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 qrResult
C# 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 IronQR yazın ve Enter'a basın.
Listeden IronQR'yi bulun ve yanındaki Yükle düğmesine tıklayın.
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 Kod için Metin Girişi
Kullanıcılar QR kodlarına kodlamak istedikleri veriyi girebilir.
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.
Margin 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 Üret
QR kodu oluşturma sürecini tetikler.
QR Kod Kaydet
QR kodunu kaydetmek için bir kaydetme diyaloğunu 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;
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 Sub
4.2 Lisans Anahtarı Yapılandırması
IronQR kütüphanesi için geçerli bir lisans anahtarını uygular:
PrivateShared Sub EnsureDirectoryExists(ByVal path AsString) IfNotSystem.IO.Directory.Exists(path) ThenSystem.IO.Directory.CreateDirectory(path) End IfEnd 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
QR kodları dizinine giden yol, uygulamanın başlangıç yolunu bir 'QR Kodlar' klasör adıyla birleştiren qrCodesDirectory olarak QR_Generator sınıfı yapıcısında tanımlanıyor.
Private Function ColorToHex(ByVal color AsSystem.Drawing.Color) AsString Return $"#{color.R:X2}{color.G:X2}{color.B:X2}"End Function
Private Function ColorToHex(ByVal color As System.Drawing.Color) As String
Return $"#{color.R:X2}{color.G:X2}{color.B:X2}"
End Function
UpdateColor metodu, seçilen rengi alır ve onaltılık dize kullanarak IronSoftware.Drawing.Color formatına dönüştürür ve seçimlere bağlı olarak QR kodunun ön veya arka plan rengini günceller. Ayrıca kullanıcı arayüzü, yeni renk tercihinin yansıtılması için güncellenir:
private voidUpdateColor(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 AsColor, ByVal display AsControl, ByVal isBackground AsBoolean) If select_color.ShowDialog() = DialogResult.OKThen Dim hexColor = ColorToHex(select_color.Color) targetColor = New Color(hexColor) display.BackColor = select_color.Color End IfEnd Sub
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 Sub
4.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 AsObject, ByVal e AsEventArgs) If select_logo.ShowDialog() = DialogResult.OKThenTry logoBmp = New AnyBitmap(select_logo.FileName) selected_logo.Image = Image.FromFile(select_logo.FileName)Catch ex AsExceptionShowError("An error occurred while loading the logo", ex.Message)EndTry End IfEnd Sub
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 Sub
4.6 QR Kod Üretimi
Kullanıcı girdilerine dayanarak QR kodları oluşturma mantığını içerir.
Private Sub btn_generate_Click(ByVal sender AsObject, ByVal e AsEventArgs)GenerateQRCode()End Sub
Private Sub btn_generate_Click(ByVal sender As Object, ByVal e As EventArgs)
GenerateQRCode()
End Sub
QrOptions nesnesi, QR kodunun hasara veya gizlenmeye karşı dayanıklılığını artıran hata düzeltme seviyesini tanımlar. CreateStyleOptions metodu, renkler, boyutlar ve logo gibi kullanıcının özel ayarlarını içeren bir QrStyleOptions nesnesi üretir. İşte yöntem detayları:
Private Function CreateStyleOptions() AsQrStyleOptions'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 QrStyleOptionsWith { .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 QrLogoWith { .Bitmap = logoBmp, .Width = 50, .Height = 50, .CornerRadius = 5 }, Nothing) }End Function
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
4.7 QR Kodunu Kaydetme
Oluşturulan QR kodunun kaydedilmesini yönetir.
private void btn_save_Click(object sender, EventArgs e){SaveQRCode();}private voidSaveQRCode(){ 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 AsObject, ByVal e AsEventArgs)SaveQRCode()End SubPrivate Sub SaveQRCode() If pictureBox.ImageIs Nothing ThenMessageBox.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.OKThenTry pictureBox.Image.Save(saveFileDialog.FileName, DetermineImageFormat(saveFileDialog.FileName))MessageBox.Show("QR Code has been saved!", "Success")Catch ex AsExceptionShowError("An error occurred while saving the QR code", ex.Message)EndTry End IfEnd Sub
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 Sub
Private Function DetermineImageFormat(ByVal filePath AsString) AsSystem.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 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
4.8 Uygulamayı Sıfırlama
Kullanıcı girdilerini temizler ve form durumunu sıfırlar.
Private Sub btn_reset_Click(ByVal sender AsObject, ByVal e AsEventArgs)ResetFields()End SubPrivate 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 = NothingEnd Sub
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 Sub
PrivateShared Sub ShowError(ByVal title AsString, ByVal message AsString)MessageBox.Show($"{title}: {message}", "Error")End Sub
Private Shared Sub ShowError(ByVal title As String, ByVal message As String)
MessageBox.Show($"{title}: {message}", "Error")
End Sub
4.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; publicQR_Generator() {InitializeComponent();SetLicenseKey();EnsureDirectoryExists(qrCodesDirectory); } private static voidSetLicenseKey() {IronQr.License.LicenseKey = "License-Key"; } private static voidEnsureDirectoryExists(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 stringColorToHex(System.Drawing.Color color) { return $"#{color.R:X2}{color.G:X2}{color.B:X2}"; } private voidUpdateColor(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 voidGenerateQRCode() { 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 QrStyleOptionsCreateStyleOptions() { 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 voidSaveQRCode() { 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.ImageFormatDetermineImageFormat(string filePath) { returnSystem.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 voidResetFields() { 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 voidShowError(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");
}
}
}
ImportsIronQrImportsIronSoftware.DrawingImportsColor = IronSoftware.Drawing.ColorNamespaceIronQR_QR_Generator_WinFormsPartialPublic Class QR_GeneratorInheritsForm Private qrCodesDirectory AsString = System.IO.Path.Combine(Application.StartupPath, "QR Codes") Private bgColor AsColor = Color.White Private color AsColor = Color.Black Private logoBmp? AsAnyBitmap = Nothing Public Sub New()InitializeComponent()SetLicenseKey()EnsureDirectoryExists(qrCodesDirectory) End Sub PrivateShared Sub SetLicenseKey()IronQr.License.LicenseKey = "License-Key" End Sub PrivateShared Sub EnsureDirectoryExists(ByVal path AsString) IfNotSystem.IO.Directory.Exists(path) ThenSystem.IO.Directory.CreateDirectory(path) End If End Sub Private Sub btn_color_Click(ByVal sender AsObject, ByVal e AsEventArgs)UpdateColor(color, txt_selected_color, False) End Sub Private Sub btn_background_Click(ByVal sender AsObject, ByVal e AsEventArgs)UpdateColor(bgColor, txt_selected_bgcolor, True) End Sub Private Function ColorToHex(ByVal color AsSystem.Drawing.Color) AsString Return $"#{color.R:X2}{color.G:X2}{color.B:X2}" End Function Private Sub UpdateColor(ByRef targetColor AsColor, ByVal display AsControl, ByVal isBackground AsBoolean) If select_color.ShowDialog() = System.Windows.Forms.DialogResult.OKThen 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 AsObject, ByVal e AsEventArgs) If select_logo.ShowDialog() = System.Windows.Forms.DialogResult.OKThenTry logoBmp = New AnyBitmap(select_logo.FileName) selected_logo.Image = Image.FromFile(select_logo.FileName)Catch ex AsExceptionShowError("An error occurred while loading the logo", ex.Message)EndTry End If End Sub Private Sub btn_generate_Click(ByVal sender AsObject, ByVal e AsEventArgs)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 AsExceptionShowError("An error occurred during QR code generation or saving", ex.Message)EndTry End Sub Private Function CreateStyleOptions() AsQrStyleOptions'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 QrStyleOptionsWith { .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 QrLogoWith { .Bitmap = logoBmp, .Width = 50, .Height = 50, .CornerRadius = 5 }, Nothing) } End Function Private Sub btn_save_Click(ByVal sender AsObject, ByVal e AsEventArgs)SaveQRCode() End Sub Private Sub SaveQRCode() If pictureBox.ImageIs Nothing ThenMessageBox.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.OKThenTry pictureBox.Image.Save(saveFileDialog.FileName, DetermineImageFormat(saveFileDialog.FileName))MessageBox.Show("QR Code has been saved!", "Success")Catch ex AsExceptionShowError("An error occurred while saving the QR code", ex.Message)EndTry End If End Sub Private Function DetermineImageFormat(ByVal filePath AsString) AsSystem.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 AsObject, ByVal e AsEventArgs)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 PrivateShared Sub ShowError(ByVal title AsString, ByVal message AsString)MessageBox.Show($"{title}: {message}", "Error") End Sub End ClassEndNamespace
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 Namespace
Adı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ç
Sonuç olarak, bu kılavuz, C# uygulamasında IronQR kütüphanesini kullanarak QR kodları oluşturma sürecinde size rehberlik etti. Projenizi Visual Studio'da kurmaktan, IronQR kütüphanesini entegre etmeye, kullanıcı dostu bir arayüz tasarlamaktan ve arka uç mantığını yazmaya kadar adımları bölerek, uygulamalarınıza QR kodu işlevi eklemenin ne kadar erişilebilir olduğunu gösterdik.
IronQR'nin yeteneklerini daha fazla keşfetmekle ilgilenenler için, IronQR'nin başlamanıza yardımcı olacak bir ücretsiz deneme sunduğunu belirtmekte fayda var. IronQR'yi projelerinize entegre etme kararı verirseniz, lisanslar $999'dan başlar ve profesyonel düzeyde QR kod üretimi için uygun maliyetli bir çözüm sunar.
Sıkça Sorulan Sorular
C# dilinde bir QR kodu üretici uygulama nasıl oluşturabilirim?
C# dilinde bir QR kodu üretici uygulama oluşturmak için IronQR kütüphanesini kullanabilirsiniz. Visual Studio'da bir Windows Forms Uygulaması kurarak başlayın, IronQR'yi NuGet aracılığıyla yükleyin ve uygulamanızın ön yüzünü tasarlayın. Renk seçimi ve logo katıştırma gibi IronQR'nin özelliklerini kullanarak QR kodu oluşturma mantığını uygulayın.
.NET QR kodu kütüphanesini kullanmanın faydaları nelerdir?
.NET QR kodu kütüphanesi olan IronQR, QR kodlarını okuma konusunda yüksek doğruluk sunan gelişmiş özellikler, QR kodu oluşturmak için özelleştirme seçenekleri ve çeşitli .NET ortamlarıyla uyumluluk sunar. Aynı zamanda QR kodu yeniden boyutlandırma ve stil verme seçeneklerine de olanak tanır.
C# dilinde QR kodları oluştururken hataları nasıl yönetebilirim?
C# dilinde, QR kodu oluşturma sırasında try-catch yapıları kullanarak düzgün bir hata yönetimi mekanizmaları uygulayarak hataları ele alabilirsiniz. IronQR, QR kodu oluşturma sırasında ortaya çıkabilecek sorunları etkin bir şekilde yöneterek sorunsuz bir hata yönetimi sağlar.
Bir QR kodu kütüphanesi kullanarak QR kodlarına logolar gömebilir miyim?
Evet, IronQR kütüphanesini kullanarak QR kodlarına logolar gömebilirsiniz. Bu özellik, QR kodlarınızın tasarımına özel logolar ekleyerek marka kimliğinizi güçlendirmenize olanak tanır.
C# uygulamasında üretilen QR kodlarını nasıl kaydedebilirim?
IronQR'nin depolama dizinlerini belirleme işlevselliğini kullanarak, C# uygulamasında üretilen QR kodlarını kaydedebilirsiniz. Bu, üretilen QR kodlarını uygulamanız içinde verimli bir şekilde yönetip depolamanıza olanak tanır.
Bir QR kodu kütüphanesi için lisans anahtarı nasıl yapılandırılır?
IronQR için lisans anahtarı yapılandırmak için, uygulamanıza lisans kodunu dahil etmeniz gerekir. Bu genellikle, satın aldığınız lisansla birlikte sağlanan belirli kod satırlarını ekleyerek kütüphaneyi etkinleştirmenizi içerir.
C# uygulamamda özel renklerle QR kodları nasıl stil verebilirim?
IronQR, renk özelleştirme özellikleri sunarak QR kodlarını özel renklerle stil vermenize olanak tanır. Uygulamanıza entegre edilmiş renk seçim diyaloglarını kullanarak, QR kodu ön planı ve arka planı için renkler seçebilirsiniz.
Visual Studio'da bir QR kodu kütüphanesi kurmanın süreci nedir?
Visual Studio'da IronQR gibi bir QR kodu kütüphanesi kurmak için NuGet Paket Yöneticisini kullanın. 'IronQR' aramasını yapın ve projeye eklemek için 'Yükle' düğmesine tıklayın. Alternatif olarak, 'Install-Package IronQR' komutunu içeren Paket Yöneticisi Konsolunu kullanın.
What is the suggested way to handle errors when using IronQR?
It's recommended to implement error handling in your application to catch exceptions that may occur during QR code generation or reading, ensuring a smooth experience.
Can I run the QR code generator application on different platforms?
Yes, with IronQR's compatibility across various .NET frameworks, you can run the QR code generator application on multiple platforms like Windows, Linux, and macOS.
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.