You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I try to print a PrintDocument with a Code128 barcode drawn, the barcode appears as just black. Could it be due to the way I've converted everything to actually get it somewhat functional? What's the correct way of doing this?
publicvoidPrintTestDocument(){// Create new BarcodeBarcodebarcode=new(){IncludeLabel=true,ForeColor=new(0F,0F,255F),BackColor=new(255F,0F,0F),};// Encode Barcode to SKImageSKImageskImage= barcode.Encode(BarcodeStandard.Type.Code128,"061200204001");// Start the Print DocumentPrintDocumentpd=new PrintDocument();
pd.PrinterSettings.PrinterName ="OneNote (Desktop)";// Demo printing
pd.PrintPage +=(sender,e)=> PrintPageHandler(e, skImage);// Print
pd.Print();}privatestaticvoidPrintPageHandler(PrintPageEventArgse,SKImageskImage){Bitmapbitmap= ToBitmap(skImage);// Calculate the position to center the image on the pageintx=(e.PageBounds.Width - bitmap.Width)/2;inty=(e.PageBounds.Height - bitmap.Height)/2;// Draw the image on the print document
e.Graphics.DrawImage(bitmap,new Point(x, y));}privatestatic Bitmap ToBitmap(SKImageskImage){// SKImage to SKPixmapSKPixmapskiaPixmap= skImage.PeekPixels();usingMemoryStreamstream=new MemoryStream();// Encode SKPixmap to bitmap
skImage.Encode(SKEncodedImageFormat.Png,100).SaveTo(stream);// Create a Bitmap from the MemoryStreamreturnnew Bitmap(stream);}}
When PrintTestDocument() is run, the below document is printed.
The text was updated successfully, but these errors were encountered:
Hi 👋
When I try to print a PrintDocument with a Code128 barcode drawn, the barcode appears as just black. Could it be due to the way I've converted everything to actually get it somewhat functional? What's the correct way of doing this?
When
PrintTestDocument()
is run, the below document is printed.The text was updated successfully, but these errors were encountered: