Bitmap.Rotate Problem - DOTNET

This is a discussion on Bitmap.Rotate Problem - DOTNET ; 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 ...

+ Reply to Thread
Results 1 to 3 of 3

Bitmap.Rotate Problem

  1. Default Bitmap.Rotate Problem

    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);
    }


    --
    www.pixafe.com


  2. Default Re: Bitmap.Rotate Problem

    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



    <info@pixafe.com> wrote in message
    news:1170964185.793965.312120@s48g2000cws.googlegroups.com...
    > 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);
    > }
    >
    >
    > --
    > www.pixafe.com
    >




  3. Default Re: Bitmap.Rotate Problem

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


    --
    Chris Tacke - Embedded MVP
    OpenNETCF Consulting
    Managed Code in the Embedded World
    www.opennetcf.com
    --


    <info@pixafe.com> wrote in message
    news:1170964185.793965.312120@s48g2000cws.googlegroups.com...
    > 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);
    > }
    >
    >
    > --
    > www.pixafe.com
    >




+ Reply to Thread

Similar Threads

  1. Google map-like bitmap problem.
    By Application Development in forum Graphics
    Replies: 3
    Last Post: 09-25-2007, 02:46 AM
  2. bitmap conversion problem
    By Application Development in forum DOTNET
    Replies: 2
    Last Post: 07-21-2007, 04:52 PM
  3. This is how I rotate an bitmap
    By Application Development in forum DOTNET
    Replies: 30
    Last Post: 06-12-2007, 01:46 AM
  4. Rotate bitmap 90
    By Application Development in forum DOTNET
    Replies: 10
    Last Post: 10-05-2006, 09:29 AM
  5. Bitmap to Clipboard problem
    By Application Development in forum DOTNET
    Replies: 4
    Last Post: 11-22-2005, 04:05 AM