Showing posts with label QR code generator. Show all posts

.NET MAUI is a powerful platform for building cross-platform mobile applications, and with the right tools and resources, it'...

.Net MAUI - QR Code Generator .Net MAUI - QR Code Generator

A blog about android developement

QR code generator

.NET MAUI is a powerful platform for building cross-platform mobile applications, and with the right tools and resources, it's easy to add barcode scanning functionality to your app. In this tutorial, we'll walk you through the steps of implementing a QR Code Generator in .NET MAUI using the Codebude - QR Coder plugin.


Quick Links:


Project Setup:

  • Launch Visual Studio 2022, and in the start window click Create a new project to create a new project.
  • In the Create a new project window, select MAUI in the All project types drop-down, select the .NET MAUI App template, and click the Next button:
  • In the configure your new project window, name your project, choose a suitable location for it, and click the Next button:
  • In the Additional information window, click the Create button:
  • Once the project is created, we can able to see the Android, iOS, Windows and other running options in the toolbar. Press the emulator or run button to build and run the app

Implementation:

QRCoder is a simple library, written in C#.NET, which enables you to create QR codes. First, we need to add the QR Coder library to our project as a dependency. To do this, open the NuGet Package Manager and search for "QRCoder". Install the package in your .NET MAUI project.


Install QRCoder

Install QRCoder nuGet package on your .NET MAUI application.

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode(InputText.Text, QRCodeGenerator.ECCLevel.L);
PngByteQRCode qRCode = new PngByteQRCode(qrCodeData);
byte[] qrCodeBytes = qRCode.GetGraphic(20);
QrCodeImage.Source = ImageSource.FromStream(() => new MemoryStream(qrCodeBytes));

The above lines only need to generate the QR code for your mobile application.

How to change the color of your QR code

The GetGraphics-method has some more overloads. The first two enable you to set the color of the QR code graphic. One uses Color-class-types, the other HTML hex color notation.

//Set color by using Color-class types
Bitmap qrCodeImage = qrCode.GetGraphic(20, Color.DarkRed, Color.PaleGreen, true);

//Set color by using HTML hex color notation
Bitmap qrCodeImage = qrCode.GetGraphic(20, "#000ff0", "#0ff000");
Full Code of MainPage:

Demo

Download Code:

You can download the code from GitHub. If you have any doubts, feel free to post a comment. If you liked this article, and it is useful to you, do like, share the article & star the repository on GitHub.

In this Post, I introduce my new Gradle Library. This Library is used to Generate QR Code Automatically for our specified input. How to ...

QR-Code Generator - Library QR-Code Generator - Library

A blog about android developement

QR code generator

QR-CODE  GENERATOR - Library
In this Post, I introduce my new Gradle Library. This Library is used to Generate QR Code Automatically for our specified input.
How to Import the Library:
Gradle:
compile 'androidmads.library.qrgenearator:QRGenearator:1.0.0'
Permission:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
How to use this Library:
After importing this library, use the following lines to use this library. The following lines are used to generated the QR Code
// Initializing the QR Encoder with your value to be encoded, type you required and Dimension
QRGEncoder qrgEncoder = new QRGEncoder(inputValue, null, QRGContents.Type.TEXT, smallerDimension);
try {
  // Getting QR-Code as Bitmap
  bitmap = qrgEncoder.encodeAsBitmap();
  // Setting Bitmap to ImageView
  qrImage.setImageBitmap(bitmap);
} catch (WriterException e) {
  Log.v(TAG, e.toString());
}
Save QR Code as Image
// Save with location, value, bitmap returned and type of Image(JPG/PNG).
QRGSaver.save(savePath, edtValue.getText().toString().trim(), bitmap, QRGContents.ImageType.IMAGE_JPEG);
For more Details Visit Here
Github Link:
Open Github
Leave Comment about this Library.