I'm writing a Pocket PC application in C#, VS2005. I'm using the .NET Compact Framework 2.0. All I want to do is load a large JPEG file (2-3MB) taken from a digital camera, and display it in a Picture Box.
When I try to do so using the following code, I get HResult -2147024882 --- "OutOfMemoryException"
Bitmap bmp = new Bitmap(@"\Storage Card\TEMP\2MBJPEG.JPG");
I know that other programs are able to do this, even if it involves making an unmanged call.
I know this can be done because other programs can do it (eg. Resco Photo Viewer). I've also seen examples that use c++ (although I'm not familiar with that language).
How can I load a large bitmap (even if it ends up being scaled down to a thumbnail)

C# - Loading a Large JPEG file (> 2Mb) - Memory Issue
Vinces
Excellent! That worked. Thank you for that Alex.
Here are the steps that i followed to get it working:
#region Using directives
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using OpenNETCF.Drawing.Imaging;
using System.IO;
#endregion
....
const string szFileName = @"\Storage Card\TEMP\2MBJPEG.JPG";
private void Form1_Load(object sender, EventArgs e)
{
IBitmapImage imageBitmap;
FileStream fsImage;
fsImage = new FileStream(
szFileName,
FileMode.Open);
imageBitmap = CreateThumbnail(
fsImage,
new Size(100, 100));
Bitmap bm = ImageUtils.IBitmapImageToBitmap(
imageBitmap);
pictureBox1.Image = bm;
}
static public IBitmapImage CreateThumbnail(Stream stream, Size size)
{
IBitmapImage imageBitmap;
ImageInfo ii;
IImage image;
ImagingFactory factory = new ImagingFactoryClass();
factory.CreateImageFromStream(
new StreamOnFile(stream),
out image);
image.GetImageInfo(out ii);
factory.CreateBitmapFromImage(
image,
(uint)size.Width,
(uint)size.Height,
ii.PixelFormat,
InterpolationHint.InterpolationHintDefault,
out imageBitmap);
return imageBitmap;
}
SintratF
Please see this:
http://groups.google.com/group/microsoft.public.dotnet.framework.compactframework/browse_frm/thread/f689578f13b24825/58a6bf7395948c0c#58a6bf7395948c0c
Dietmar Kupke
I would suggest posting question about that on the mentioned NG. Or you can debug the code and find our what's going on.
noob
CPG
TonyTheCalypsoKid
The Imaging libraries in the SDF v2 should be able to do that.
http://www.opennetcf.org/sdf
Take a look at Alex's blog for details:
http://blog.opennetcf.org/afeinman/
ceto