Home : Use ReadRegion in TiffDecoder
Q10272 - HOWTO: Use ReadRegion in TiffDecoder

Reading an image region rather than the entire image can prevent the program from running out of memory. It can also be used as an efficient crop for a large image. The method ReadRegion() is available with some of our decoders. The most notable being the TiffDecoder. Here is a sample of using the TiffDecoder to open the upper left quadrant of an image file:

C#

  OpenFileDialog open = new OpenFileDialog();

  open.ShowDialog();

  using(FileStream fs = new FileStream(open.FileName, FileMode.Open))

  {

    TiffDecoder decoder = new TiffDecoder();

    if (decoder.IsValidFormat(fs))

    {

      ImageInfo info = decoder.GetImageInfo(fs);

      AtalaImage img = decoder.ReadRegion(fs, new Rectangle(0, 0, info.Size.Width / 2, info.Size.Height / 2), 0, null);

      imageViewer1.Image = img;

    }

    else

    {

      MessageBox.Show("This file is not in the Tiff Format");

    }

  }

 

VB.NET

Dim open As New OpenFileDialog()

open.ShowDialog()

Using fs As New FileStream(open.FileName, FileMode.Open)

    Dim decoder As New TiffDecoder()

    If decoder.IsValidFormat(fs) Then

        Dim info As ImageInfo = decoder.GetImageInfo(fs)

        Dim img As AtalaImage = decoder.ReadRegion(fs, New Rectangle(0, 0, info.Size.Width / 2, info.Size.Height / 2), 0, Nothing)

        imageViewer1.Image = img

    Else

        MessageBox.Show("This file is not in the Tiff Format")

    End If

End Using

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.

Powered By InstantKB.NET v1.3
Copyright © 2002, 2019. InstantASP Ltd. All Rights Reserved