I write a method which reduce the color depth (GIF convertion) and set the resolution to 600pixel from a Bitmap.
The color depth convertion works fine but the resolution set is not working.
<script runat="server" language="C#">
public static void Convert(Bitmap oldbmp, String path)
{
System.Drawing.Bitmap bm8Bit;
using (MemoryStream ms = new MemoryStream())
{
oldbmp.Save(ms, ImageFormat.Gif);
ms.Position = 0;
bm8Bit = (System.Drawing.Bitmap) System.Drawing.Image.FromStream(ms);
bm8Bit.SetResolution(600, 600);
bm8Bit.Save(path, System.Drawing.Imaging.ImageFormat.Bmp);
return;
}
}
</script>
I think you can set resolution only on new Bitmap, that wan't saved before, so if you have exiting bitmap, you need to copy it to new Bitmap instance:
Bitmap imgCopy = new Bitmap(img);
imgCopy.SetResolution(600.0f,600.0f);
Read here: http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.setresolution.aspx
Use this method to set the desired resolution on a newly created bitmap. Changing the resolution of the image does not change its physical size.