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