For Programmers: Free Programming Magazines  


Home > Archive > C# > May 2005 > Resize bitmaps









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Resize bitmaps
jill-connie

2005-05-03, 12:17 pm

I want to resize a bitmap, but that seems to be easier said than done.

My original bitmap has pixel format 8bpp indexed.

I would think that creating a new bitmap with the constructor
Bitmap compressedImage = newBitmap( Image original, original.Width/2, original.Height/2 )
would do the trick, but it changes the format to 32 bpp Argb, even though it says in my book that
"the new bitmap inherits the pixel format of the existing bitmap".

So, I thought I could clone my compressedImage:
Bitmap cloneCompressedImage = compressedImage.Clone( new Rectangle( 0,0,compressedImage.Width,compressedImage.Height),
System.Drawing.Imaging.PixelFormat.Format8bppIndexed ) ;
but it raises an OutOfMemory exception, no matter which values I try for width and height.

Just for fun I tried to clone my original image:
Bitmap cloneOriginalImage = original.Clone( new Rectangle( 0,0,original.Width,original.Height),
System.Drawing.Imaging.PixelFormat.Format8bppIndexed ) ;
It works fine, but if I try to set the correct dimensions I get only a portion of the original(of course).

I've also tried using
Graphics gr = Graphics.FromImage( original );
but got an exeption saying "A Graphics object cannot be created from an image that has an indexed pixel format"


If anyone has an idea on how to maintain the pixel format, or maybe has another way of doing this, - please let me know!
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com