private void BarCodeListGenerator(BarcodeDto data) { var barcodeWriterPixelData = new BarcodeWriterPixelData { Format = BarcodeFormat.CODE_128, Options = new ZXing.Common.EncodingOptions { Height = 280, Width = 280, Margin = 2, } }; foreach (var code in data.Code) { var pixelData = barcodeWriterPixelData.Write(code); Bitmap bitmap = new Bitmap(pixelData.Width, pixelData.Height, PixelFormat.Format32bppRgb); MemoryStream memoryStream = new MemoryStream(); var bitmapData = bitmap.LockBits(new Rectangle(0, 0, pixelData.Width, pixelData.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb); System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length); bitmap.Save(memoryStream, ImageFormat.Png); byte[] byteImage = memoryStream.ToArray(); SaveBarcode(code, byteImage); } }
public IActionResult BarCodeGenerator(BarcodeDto data) { BarCodeListGenerator(data); return(Ok()); }