C
C#2mo ago
Silme94

Bad Bitmap quality

on the right, the original image, on the left, the saved image from bitmap (im doing a functionnality to add image to image). As you can see, there is a big quality difference. Is there a way to keep the same quality?
using (Bitmap bitmap = new Bitmap(pageImage.Width, pageImage.Height))
{

bitmap.SetResolution(96, 96);

using (Graphics g = Graphics.FromImage(bitmap))
{

g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;


var rect = new Rectangle(0, 0, pageImage.Width, pageImage.Height);
pageImage.DrawToBitmap(bitmap, rect);
}


bitmap.Save(@"C:\Users\silme\Desktop\img.png", ImageFormat.Png);
}
using (Bitmap bitmap = new Bitmap(pageImage.Width, pageImage.Height))
{

bitmap.SetResolution(96, 96);

using (Graphics g = Graphics.FromImage(bitmap))
{

g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;


var rect = new Rectangle(0, 0, pageImage.Width, pageImage.Height);
pageImage.DrawToBitmap(bitmap, rect);
}


bitmap.Save(@"C:\Users\silme\Desktop\img.png", ImageFormat.Png);
}
No description
1 Reply
Sehra
Sehra2mo ago
the picturebox you use likely render at 96 dpi on the screen. loading the higher res image in the picturebox scaled it down, then drawing it to a bitmap of lower res make it blurry. the graphics object you create is never used, you still render to the bitmap

Did you find this page helpful?