I am not a C# developer (embedded developer with C) but I have been forced to do a project which requires me to add a barcode to a PNG and print it,
if the resolution of the picture is high, the picture will be printed huge, covering a couple of labels (the printer works in 2 labels per row and 7 columns for each print command, a total of 14 labels)
now when I resize it, the picture will fit, however, the Quality will drop dramatically, and it's unreadable
this is the code I am using (The code is from Stackoverflow somewhere)
static Bitmap ScaleImage(Bitmap bmp, int maxWidth, int maxHeight)
{
var ratioX = (double)maxWidth / bmp.Width;
var ratioY = (double)maxHeight / bmp.Height;
var ratio = Math.Min(ratioX, ratioY);
var newWidth = (int)(bmp.Width * ratio);
var newHeight = (int)(bmp.Height * ratio);
var newImage = new Bitmap(newWidth, newHeight);
using (var graphics = Graphics.FromImage(newImage))
graphics.DrawImage(bmp, 0, 0, newWidth, newHeight);
return newImage;
}
private void button1_Click(object sender, EventArgs e)
{
var image = new Bitmap("C:\\Users\\gilani\\Desktop\\BarCodeCreator\\sad2.bmp");
pictureBox1.Image = ScaleImage(image, 100, 80);
}
private void button2_Click(object sender, EventArgs e)
{
PrintDialog print = new PrintDialog();
PrintDocument doc = new PrintDocument();
doc.PrintPage += Doc_PrintPage;
print.Document = doc;
if (print.ShowDialog(this) == DialogResult.OK)
{
doc.Print();
}
}
private void Doc_PrintPage(object sender, PrintPageEventArgs e)
{
int start_right = 32;
int start_Top = 0;
Bitmap bitmp = new Bitmap(pictureBox1.Image), pictureBox1.Image.Height));
e.Graphics.DrawImage(bitmp, start_right, start_Top);
bitmp.Dispose();
}
I need a way to preserve the Resolution/ Quality but print in much smaller size (probably its caled scale) I might even be going the whole road wrong, please inform me if I need to take another way
Doc_PrintPage
there was an error, and my edit made it worse? I believe