How to Display part of a large Image?

I have a image with 2MB, I only want to get part of the image and display in a picturebox without load the whole file, how to

(I'm a Chinese boy, so my Eng is not very well, forgive me)

hcaihao@gmail.com



Answer this question

How to Display part of a large Image?

  • IceAngel89

    Have you looked into IImage.Draw() and “OPTIONAL const RECT* srcRect”

  • mido h

    I have tried IImage.Draw() method, but still get oom error when the image is a little large.
  • PedroCGD

    Really That's cool, could you give me a piece of code I know the code below can create a thumbnail, but how to cut the image

    FileStream fsImage = new FileStream("a.jpg", FileMode.Open);
    IBitmapImage imageBitmap = ImageUtils.CreateThumbnail(fsImage, new Size(240, 266));

    Bitmap bm = ImageUtils.IBitmapImageToBitmap(imageBitmap);
    picBox_地 .Image = bm;

    I once try to use IImage.Draw, but failure too.


  • tShunnar

    The following code should do what you need. It works for me:

    public void ShowImage(Image bmp, PictureBox pb, int x, int y, int cx, int cy)
    {
    Bitmap b;
    Graphics g;

    b = new Bitmap(cx, cy);
    g = Graphics.FromImage(b);

    g.DrawImage(bmp, 0, 0, new Rectangle(x, y, cx, cy), GraphicsUnit.Pixel);

    // Don't forget to dispose the current image
    if (pb.Image != null)
    pb.Image.Dispose();

    pb.Image = b;

    g.Dispose();
    }


  • Przemek G.

    Thank you, Sergey Kuryata. The code can show part of a image, but not a large image. If you load a large image into memory, it will out of memory.


  • danadanny

    Thanks for your reply, I think there is some ambiguous with my express. I mean I want show a rectangle area in a image, such as a quarter.
  • Mike Wilson

    Does the "loading parts of the large image" explain for thumbnails function I think it isn't a introduction for a new function, right

    There are some notes about this topic in OpenNetcf.org's forum, but no answer. I doubt whether it can do it.


  • Henrik Dahl

    Use Imaging API. OpenNetcf.org has managed wrapper.



  • ProjectDev

    I don't have a sample for you but I’m fairly confident Imaging API can handle parts of the image.

    Since you're using OpenNetcf.org let me quote some from it:

    1. Thumbnails, loading parts of the large image

    Loading an image in Imaging API is achieved via calls to decoders - COM objects implementing IImageDecoder interface. The basic imaging interface IImage uses decoders to load image data. Most of the decoders support loading partial image, discarding the unnecessary data.

    If you’d like to figure it out look through Imaging API methods and interfaces and see which might be of use. On a quick look perhaps IImage.Draw() and “OPTIONAL const RECT* srcRect” might just do.

    I would also suggest posting a question on OpenNetcf.org's forum, I'm sure Alex would be able to answer it right away.



  • Part Time Australian

    Let me make sure I understand the issue.

    You have a bitmap stored in the file system. You need to be able to display a section of that bitmap without loading the entire bitmap into memory. Is that correct

    If so, a couple of questions:

    • Do you supply the bitmap or does it come from a third party
    • Is the bitmap static or does it change on a regular basis
    • How does the user interact with the image Is it scrolled in chunks Is it panned

    Dan



  • Zach7

    No, your question is pretty clear. And answer is valid even for quarter of the image - Imaging API.



  • UnKnown Nick

    It's a simple jpge file with 10000*0000 px, I want scroll it in my mobile application, thanks.
  • brian_tsim

    Can anybody give me a answer Thanks!!!
  • How to Display part of a large Image?