# Generate QR codes with C# .NET

Nutrient.NET SDK (formerly GdPicture.NET) enables you to generate one-dimensional (1D or linear) and two-dimensional (2D) barcodes.

Nutrient.NET SDK supports all 1D barcode formats and the following 2D barcode formats:

- Aztec Code

- Data Matrix

- MaxiCode

- Micro QR

- PDF417

- QR

To generate a QR barcode, follow the steps below:

1. Create a `GdPictureImaging` object.

2. Set the encoding mode of the barcode with the `BarcodeQREncodingMode` enumeration, and store it in a variable. Use `BarcodeQREncodingModeUndefined` to let the engine determine the most appropriate encoding mode for the input data.

3. Set the error correction level with the `BarcodeQRErrorCorrectionLevel` enumeration, and store it in a variable.

4. Compute the size of the barcode with the `BarcodeQRGetSize` method of the `GdPictureImaging` object, and store it in a variable. This method takes the following parameters:
   - The data encoded in the barcode.
   - The encoding mode.
   - The error correction level.
   - An output parameter that defines the version of the barcode.
   - The number of modules considered quiet zone around the barcode. The recommended value is `4` or more.
   - The size of each module in pixels. The recommended value is `4` or more.

5. Create an empty GdPicture image with the `CreateNewGdPictureImage` method of the `GdPictureImaging` object. This method takes the following parameters:
   - The width of the image in pixels.
   - The height of the image in pixels.
   - The bit depth of the image.
   - The background color of the image. Use the `ARGB` method of the `GdPictureImaging` object to specify the color with the ARGB standard. For example, for a white background, set `gdpictureImaging.ARGB(255, 255, 255)`.

6. Write the barcode to the empty image with the `BarcodeQRWrite` method of the `GdPictureImaging` object. This method takes the following parameters:
   - The image ID of the newly created image.
   - The data encoded in the barcode.
   - The encoding mode.
   - The error correction level.
   - The version of the barcode.
   - The number of modules considered quiet zone around the barcode. The recommended value is `4` or more.
   - The size of each module in pixels. The recommended value is `4` or more.
   - The distance between the left side of the image and the barcode in pixels.
   - The distance between the top side of the image and the barcode in pixels.
   - The angle of the barcode.
   - The color of the symbols on the barcode. Use the `ARGB` method of the `GdPictureImaging` object to specify the color with the ARGB standard. For example, for black, set `gdpictureImaging.ARGB(0, 0, 0)`.
   - The background color of the barcode. Use the `ARGB` method of the `GdPictureImaging` object to specify the color with the ARGB standard. For example, for white, set `gdpictureImaging.ARGB(255, 255, 255)`.

7. Save the image as a PNG file with the `SaveAsPNG` method of the `GdPictureImaging` object.

8. Release unnecessary resources.

The example below generates a QR barcode:

### C#

```csharp

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
// Set the encoding mode of the barcode.
BarcodeQREncodingMode encodingMode = BarcodeQREncodingMode.BarcodeQREncodingModeUndefined;
// Set the error correction level.
BarcodeQRErrorCorrectionLevel errorCorrectionLevel = BarcodeQRErrorCorrectionLevel.BarcodeQRErrorCorrectionLevelM;
// Compute the size of the barcode.
int size = gdpictureImaging.BarcodeQRGetSize("0123456789", encodingMode, errorCorrectionLevel, out int version, 4, 8);
// Create an empty GdPicture image.
int imageID = gdpictureImaging.CreateNewGdPictureImage(size, size, 32, gdpictureImaging.ARGB(255, 255, 255));
// Write the barcode to the empty image.
gdpictureImaging.BarcodeQRWrite(imageID, "0123456789", encodingMode, errorCorrectionLevel, version, 4, 8, 0, 0, 0, gdpictureImaging.ARGB(0, 0, 0), gdpictureImaging.ARGB(255, 255, 255));
// Save the image as a PNG file.
gdpictureImaging.SaveAsPNG(imageID, @"C:\temp\output.png");
// Release unnecessary resources.
gdpictureImaging.ReleaseGdPictureImage(imageID);

```

### VB.NET

```vb

Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    ' Set the encoding mode of the barcode.
    Dim encodingMode As BarcodeQREncodingMode = BarcodeQREncodingMode.BarcodeQREncodingModeUndefined
    ' Set the error correction level.
    Dim errorCorrectionLevel As BarcodeQRErrorCorrectionLevel = BarcodeQRErrorCorrectionLevel.BarcodeQRErrorCorrectionLevelM
    ' Compute the size of the barcode.
    Dim version As Integer = Nothing
    Dim size As Integer = gdpictureImaging.BarcodeQRGetSize("0123456789", encodingMode, errorCorrectionLevel, version, 4, 8)
    ' Create an empty GdPicture image.
    Dim imageID As Integer = gdpictureImaging.CreateNewGdPictureImage(size, size, 32, gdpictureImaging.ARGB(255, 255, 255))
    ' Write the barcode to the empty image.
    gdpictureImaging.BarcodeQRWrite(imageID, "0123456789", encodingMode, errorCorrectionLevel, version, 4, 8, 0, 0, 0, gdpictureImaging.ARGB(0, 0, 0), gdpictureImaging.ARGB(255, 255, 255))
    ' Save the image as a PNG file.
    gdpictureImaging.SaveAsPNG(imageID, "C:\temp\output.png")
    ' Release unnecessary resources.
    gdpictureImaging.ReleaseGdPictureImage(imageID)
End Using

```

#### Used methods and properties

- [`ARGB`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureImaging~ARGB.html)

- [`BarcodeQRErrorCorrectionLevel`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.BarcodeQRErrorCorrectionLevel.html)

- [`BarcodeQRGetSize`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureImaging~BarcodeQRGetSize.html)

- [`BarcodeQRWrite`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureImaging~BarcodeQRWrite.html)

- [`BarcodeQREncodingMode`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.BarcodeQREncodingMode.html)

- [`CreateNewGdPictureImage`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureImaging~CreateNewGdPictureImage.html)

- [`SaveAsPNG`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureImaging~SaveAsPNG.html)

- [`ReleaseGdPictureImage`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureImaging~ReleaseGdPictureImage.html)

#### Related topics

- [Load a file](/guides/dotnet/load-a-file.md)

- [Save a file](/guides/dotnet/save-a-file.md)

---

## Related pages

- [Generate Aztec barcodes in C# .NET](/guides/dotnet/barcodes/generation/aztec-code.md)
- [Generate MaxiCode barcodes in C# .NET](/guides/dotnet/barcodes/generation/maxicode.md)
- [Generate 1D barcodes in C#](/guides/dotnet/barcodes/generation/1d-linear.md)
- [Generate barcodes in C#](/guides/dotnet/barcodes/generation.md)
- [Generate Data Matrix barcodes in C# .NET](/guides/dotnet/barcodes/generation/datamatrix.md)
- [Generate PDF417 barcodes in C# .NET](/guides/dotnet/barcodes/generation/pdf417.md)
- [Generate Micro QR codes in C# .NET](/guides/dotnet/barcodes/generation/microqr.md)
- [Write a 1D barcode to an image](/guides/dotnet/barcodes/generation/write-1d-barcode-to-image.md)
- [Write a QR code to an image](/guides/dotnet/barcodes/generation/write-qr-code-to-image.md)

