i try to create a barcode and save it as picture.
The Issue is now that i cant give the barcode a fix image-height and -width.
I can size the image himself, but i cant find a possibility to maximize the barcode in the picture.
The barcode shouold fill the full height and width of the picture.
Here is my example code:
- Code: Select all
var barSet = new Spire.Barcode.BarcodeSettings()
{
Type = Spire.Barcode.BarCodeType.Code39,
Data = "harglgargl",
ShowText = false,
AutoResize = false,
ImageWidth = 200,
ImageHeight = 200,
Unit = SkiaSharp.System.Drawing.GraphicsUnit.Pixel
};
var barcode = new Spire.Barcode.BarCodeGenerator(barSet);
var skImage = barcode.GenerateImage();
// Translate SKImage to bitmap
var bitmap = new System.Drawing.Bitmap(skImage.Width, skImage.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
var data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, bitmap.PixelFormat);
// copy
using (var pixmap = new SkiaSharp.SKPixmap(new SkiaSharp.SKImageInfo(data.Width, data.Height), data.Scan0, data.Stride))
{
skImage.ReadPixels(pixmap, 0, 0);
}
bitmap.UnlockBits(data);
bitmap.Save(@"C:\Temp\test.bmp");
I have to modify the SKImage to bitmap to save to filesystem because the GenerateImage-method returns a SKImage-Type.
best wishes
Joachim