/// <summary> /// Creates a black & white PNG of the QR code, using 1-bit grayscale. /// </summary> public byte[] GetGraphic(int pixelsPerModule) { using (var png = new PngBuilder()) { var size = QrCodeData.ModuleMatrix.Count * pixelsPerModule; png.WriteHeader(size, size, 1, PngBuilder.ColorType.Greyscale); png.WriteScanlines(DrawScanlines(pixelsPerModule)); png.WriteEnd(); return(png.GetBytes()); } }
/// <summary> /// Creates a black & white PNG of the QR code, using 1-bit grayscale. /// </summary> public byte[] GetGraphic(int pixelsPerModule, bool drawQuietZones = true) { using (var png = new PngBuilder()) { var size = (this.QrCodeData.ModuleMatrix.Count - (drawQuietZones ? 0 : 8)) * pixelsPerModule; png.WriteHeader(size, size, 1, PngBuilder.ColorType.Greyscale); png.WriteScanlines(this.DrawScanlines(pixelsPerModule, drawQuietZones)); png.WriteEnd(); return(png.GetBytes()); } }
/// <summary> /// Creates 2-color PNG of the QR code, using 1-bit indexed color. Accepts 3-byte RGB colors for normal images and 4-byte RGBA-colors for transparent images. /// </summary> public byte[] GetGraphic(int pixelsPerModule, byte[] darkColorRgba, byte[] lightColorRgba) { using (var png = new PngBuilder()) { var size = this.m_xCodeData.ModuleMatrix.Count * pixelsPerModule; png.WriteHeader(size, size, 1, PngBuilder.ColorType.Indexed); png.WritePalette(darkColorRgba, lightColorRgba); png.WriteScanlines(this.DrawScanlines(pixelsPerModule)); png.WriteEnd(); return(png.GetBytes()); } }