How can I change an image file size to desired size ? Like an image of 800KB into 100KB ?
I have an image of 3MB Dimensions: (2560 X 1600) with 300 dpi and bit depth of 24. I simply read it in Bitmap change its resolution to 150 dpi and save with new name with thinking that may reduce it to almost half of its original but the new file keeps same size and dpi SetResolution donot create any effect.
Bitmap image = Bitmap.FromFile("myPic.jpeg");
image.SetResolution(96, 96);
image.Save("newPic.jpeg");
Then I used this code
// Reads Image
Bitmap image = Bitmap.FromFile("myPic.jpeg");
// Sets canvas with new dpi but same dimensions and color depth
Bitmap canvas = new Bitmap(image.Width, image.Height, PixelFormat.Format24bppRgb);
canvas.SetResolution(150, 150);
// Draw image on canvas through graphics
Graphics graphics = Graphics.FromImage(canvas);
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height),
new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
// Saved Image
bitmap.Save("newPic.jpeg");
Here dpi got changed for new file but file size jumps to 7.84MB
Where is the fault? Does dpi have any effect on file size ?
Thank you for your consideration. Stay Blessed