OpenNETCF.Drawing.Imaging

  • Thread starter Thread starter Tomppa
  • Start date Start date
T

Tomppa

I have included this im my project but cannot figure out how to:

Load a Bitmap given a FileName

Get a Bitmap as a Thumbnail

Populatethe ImageInfo

Get info from PropertyItem
 
I think I am moving in the right direction now

OpenNETCF.Drawing.Imaging.ImagingFactory iFactory = new
OpenNETCF.Drawing.Imaging.ImagingFactory();

OpenNETCF.Drawing.Imaging.IImage iiImage;

iFactory.CreateImageFromFile(FilePath, out iiImage);

OpenNETCF.Drawing.Imaging.ImageInfo imageInfo;

iiImage.GetImageInfo(out imageInfo);
 
I am using this for displaying an image on the screen.



Without the top GC.Collect() I eventually get OOM errors.



Am I using the objects efficiently? Is it necessary to create the
iImageThumb or can I just use iImage to create my iBmp?



I just have to say THANKS to OpenNetCF for this great piece of work!



My code below:



Rectangle ClientRectangle = new Rectangle(0, 0,
Screen.PrimaryScreen.WorkingArea.Width,
Screen.PrimaryScreen.WorkingArea.Height);



GC.Collect();

ImagingFactory iFactory = new ImagingFactory();

IImage iiImage;

iFactory.CreateImageFromFile(FilePath, out iiImage);

OpenNETCF.Drawing.Imaging.ImageInfo imageInfo;

iiImage.GetImageInfo(out imageInfo);



uint width, height;

width = (uint)ClientRectangle.Width;

height = width * imageInfo.Height / imageInfo.Width;

if (height > ClientRectangle.Height)

{

height = (uint)ClientRectangle.Height;

width = height * imageInfo.Width / imageInfo.Height;

}



OpenNETCF.Drawing.Imaging.IImage iiImageThumb;

iiImage.GetThumbnail(width, height, out iiImageThumb);



IBitmapImage iBmp;

iFactory.CreateBitmapFromImage(iiImageThumb, width, height,
System.Drawing.Imaging.PixelFormat.Format24bppRgb,
InterpolationHint.InterpolationHintDefault, out iBmp);

try

{

picMain1.Image = ImageUtils.IBitmapImageToBitmap(iBmp);

}

catch

{

picMain1.Image = null;

GC.Collect();

picMain1.Image = ImageUtils.IBitmapImageToBitmap(iBmp);

}
 
The reason your application is eating memory is because you are not
disposing of the Bimap object
Replace this:
picMain1.Image = null;

GC.Collect();

picMain1.Image = ImageUtils.IBitmapImageToBitmap(iBmp);
with this:
Bitmap bTemp = picMain1.Image;

picMain1.Image = null;

if ( bTemp != null )
bTemp.Dispose();

picMain1.Image = ImageUtils.IBitmapImageToBitmap(iBmp);





Tomppa said:
I just have to say THANKS to OpenNetCF for this great piece of work!

You are welcome
 
Back
Top