Bitmap.Rotate Problem

  • Thread starter Thread starter info
  • Start date Start date
I

info

Hi,
when i use the attached method to rotate a bitmap and save it back to
disk i always get an IO.Exception because the given file is in use by
another process. I think the Bitmap.Rotate Method in SDF fails to free
the file. Or is my code wrong?
Thank you for any hints,
Alex


public static void RotateImage( string pathImage, float Angle )
{
IImage image;
m_ImageFactory.CreateImageFromFile(pathImage, out image);

ImageInfo ii;
image.GetImageInfo(out ii);

IBitmapImage bitmapImage;
m_ImageFactory.CreateBitmapFromImage(image,
(uint)ii.Width,
(uint)ii.Height,
ii.PixelFormat,
InterpolationHint.InterpolationHintDefault,
out bitmapImage );

Bitmap b = ImageUtils.IBitmapImageToBitmap(bitmapImage);
Bitmap b2 = ImageUtils.Rotate(b, Angle);

b2.Save( pathImage, System.Drawing.Imaging.ImageFormat.Bmp);
}
 
Well, if the SDF uses "new Bitmap (filename)", then that call doesn't 'free
the file'. Yes, this is a pretty big bug IMHO, so hopefully someone from
Microsoft will see this and fix their code.

BTW: I haven't look at this piece of the SDK code, but why not download it,
modify it, and change (assuming they use "new Bitmap (filename)"):

new Bitmap (filename)

to...

using (FileStream fs = new FileStream (filename))
{
bmp = new Bitmap (fs);
}

That'll work.

Hilton
 
I just looked at our code, and CreateImageFromFile is a direct passthrough
to COM, so we're not leaving the file open.
 
Back
Top