Hi,
can any one tell me, how to load the highresolution images in windows mobile using c#. i am getting outofmemoryexception for that.
Hi,
can any one tell me, how to load the highresolution images in windows mobile using c#. i am getting outofmemoryexception for that.
Use IImagingFactory and IImage, they are com objects that were introduced in WCE 5.0.
You will have to write com wrappers for them, or use OpenNETCF which has them already.
See here for a blog post from Chris Lorton on alphablending and the imaging factory classes and how to use them from .net
This code shows a form with a 2mb jpg image (3000x2000 or so) on a form at 240x320, without any OOM exceptions. Obviously you will need to tidy it up to dispose of the bmp and release the com objects etc. but it does work and I have tried it on the wm6.5 emulator.
public partial class Form1 : Form
{
IImage smallImage;
Bitmap bmp = new Bitmap(240, 320);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
IImage fullSizeImage;
IImagingFactory factory = new ImagingFactoryClass();
factory.CreateImageFromFile(@"\My Documents\My Pictures\luminous opera house.jpg", out fullSizeImage);
fullSizeImage.GetThumbnail(240, 320, out smallImage);
using (Graphics gfx = Graphics.FromImage(bmp))
{
IntPtr hdc = gfx.GetHdc();
try
{
smallImage.Draw(hdc, new Rectangle(0, 0, 240, 320), IntPtr.Zero);
}
finally
{
gfx.ReleaseHdc(hdc);
}
}
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawImage(bmp, 0, 0);
}
}