How to load multipage tiff file and display each of the images in a picturebox so as

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amyS
    New Member
    • Jan 2015
    • 1

    How to load multipage tiff file and display each of the images in a picturebox so as

    I used the following code:
    Code:
    Image im = Image.FromFile(opendialog1.fileName);
            IList images = new ArrayList();
            int count
    =im.GetFrameCount(FrameDimension.Page);
          for(int i=0; i < count; i++)
    {
    	
    	im.SelectActiveFrame(FrameDimension.Page, i);
    	MemoryStream m = new MemoryStream();
    	im.Save(m, ImageFormat.Bmp); 
    	images.Add( Image.FromStream(m));
       // m.SetLength(0);
      // m = null;
       m.Close();
       im.Dispose();
    }
            for(int im=0;im<count;im++)
            {
                pictureBox1.Image = (Bitmap)images[0];
            }
            
            images.Clear();
    but it is giving me error :"out of memory "at the line
    Image im = Image.FromFile( opendialog1.fil eName);
    Can anyone help me out from this problem?Is there any other way to accomplish my task?
    Thanks in advance1
    Last edited by Rabbit; Jan 7 '15, 05:24 AM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Tim Kalu
    New Member
    • Mar 2015
    • 1

    #2
    Out of memory errors when using Image.FromFile( ) can happen for a variety of reasons.

    First, there's the obvious reason of trying to load a huge image file such as TIFF with many pages. If your images are huge, it might not be a good idea to use the System.Drawing. Image class because it's not designed for such images. In that case, you're better off using a dedicated imaging library such as Leadtools or LibTIFF.

    If it's not caused by huge images you can find some possible reasons, like running out of handles, in this discussion thread:
    I have an image uploader and cropper which creates thumbnails and I occasionally get an Out Of Memory exception on the following line: Dim bm As Bitmap = System.Drawing.Image.FromFile(imageFile) The

    Comment

    Working...