Imrpove条形码图像质量PNG

时间:2017-05-18 15:07:20

标签: c# asp.net-core zxing

我目前正在使用ZXing.Net生成CODE_128(在文档中说明符合GS1-128条形码)。我正在使用的代码如下:

BarcodeWriterPixelData writer = new BarcodeWriterPixelData()
{
    Format = BarcodeFormat.CODE_128,
    Options = new ZXing.Common.EncodingOptions
    {
        Width = 280,
        Height = 80
    }
};
var pixelData = writer.Write(packageModel.TrackingId.PrintValue);

using (var bitmap = new Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
{
    using (var ms = new System.IO.MemoryStream())
    {
        var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
        try
        {
            // we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image   
            System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length);
        }
        finally
        {
            bitmap.UnlockBits(bitmapData);
        }

        // PNG or JPEG or whatever you want
        bitmap.SetResolution(100F, 100F);
        drawing.DrawImage(bitmap, new Rectangle(10, 255, 280, 80));
    }
}

这将创建下面的图像

Barcode Generated by Code

出于某种原因,我的条形码模糊不清,上面有灰色阴影。我甚至将条形码分辨率设置为100DPI x 100DPI,以使其对打印机友好。

我的问题: 我可以在代码中添加什么来使条形码看起来更清晰,更模糊?

0 个答案:

没有答案