Reputation: 1082
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>
Upvotes: 0
Views: 4720
Reputation: 1356
Hey its always good to try to write our own solution but their is a library available which is easy to implement and works really great
you might want to use it, you can download it from here and it have very good documentation too.
http://imageresizing.net/download
Upvotes: 1
Reputation: 8540
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.
Upvotes: 2