How to load the high resolution images in windows

2019-09-21 08:04发布

问题:

Can any one tell me, how to load the high resolution images in windows mobile using C#. I am getting OutOfMemoryException for that.

回答1:

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



回答2:

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


回答3:

Here's a blog entry that covers loading large images and then zooming in on parts of them.