C# Imrpove条码图像质量PNG
我目前正在使用ZXing.Net生成代码_128(文档中说它符合GS1-128条形码)。我使用的代码如下所示:C# Imrpove条码图像质量PNG,c#,asp.net-core,zxing,C#,Asp.net Core,Zxing,我目前正在使用ZXing.Net生成代码_128(文档中说它符合GS1-128条形码)。我使用的代码如下所示: BarcodeWriterPixelData writer = new BarcodeWriterPixelData() { Format = BarcodeFormat.CODE_128, Options = new ZXing.Common.EncodingOptions { Width = 280, Height = 80
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));
}
}
这将创建下面的图像
由于某种原因,我的条形码变得模糊,上面有灰色阴影。我甚至将条形码分辨率设置为100DPI x 100DPI,以便于打印机使用
我的问题:
我可以向代码中添加什么使条形码看起来清晰和不模糊 在纸上打印时,100 dpi并没有那么大。显示器等具有75-90-ish DPI(即1680x1050像素和22英寸显示器=90 DPI).对于打印,可使用200-300 dpisuitable@Tseng我会试试的,谢谢你的建议。这不是一个直接的答案,但如果可能的话,你应该改成二维码。我在打印报告上都用过二维码,二维码扫描起来更好。100 dpi在纸上打印时没有那么多。显示器等有75-90-ish dpi(即1680x1050像素和22“监视器=90 dpi)。对于打印,需要200-300 dpisuitable@Tseng我会试试的,谢谢你的建议。不是直接的回答,但是如果可能的话,你应该改成二维码。我在打印报告和二维码上都用过,扫描起来更好。