3

Is this possible or do I have to use WPF. I am new to Winforms and have created a couple simple applications, now I need to read a TIFF file and then display a subsection of it...

I tried doing something like this:

Graphics g = e.Graphics;
Bitmap b = new Bitmap(Image.FromFile(@"W:\ILHSR_Merged_2011\compressed\overviews\ILHSR11_0405-101-1.tif"));
g.DrawImage(b, 10, 10, 350, 300);

But I get out of memory exceptions. Can someone point me to some readin, or is this simply something that should be developed in WPF.

John Saunders
  • 160,644
  • 26
  • 247
  • 397

2 Answers2

4

I think you need to implement you own TIFF loader using libTiff.

TIFF image format allow to store image data in tiles. LibTiff allows you to load single tiles: in this way you can display only portion of the image (without decoding the entire TIFF!, that can have prohibitive sizes).

Unfortunately, I don't think that .NET imaging supports that TIFF feature. My suggestion is to wrap libTiff in a library written in C++/CLI, and integrate it in your application.

(Due comment: if some existing library has already wrapped libTiff, and its interface match nicely with your application, even the better)

Luca
  • 11,646
  • 11
  • 70
  • 125
2

If you need to display parts, consider using tiled Tif files, and possibly even image pyramids (see TIF pyramid for background info on how to create/use them) tif files. All of these can be read with LibTiff and LibTiff.NET

Of course this depends on how often you need to do it. My experience is that very large bitmaps cannot be displayed properly using 32bit windows versions, unless the file itself is tiled. I have made a wrapper for LibTiff.NET, which allows Tile access also for non tiled (uncompressed, or line based) files. Of course, access is slower then; you'd need to read the entire rows which are on display. Still response time was reasonable for gigapixel images.

BitMiracle LibTiff.NET mentioned in previous post/comment works great: see How to implement pan/zoom on gigapixel bitmaps? and How to implement pan/zoom on gigapixel bitmaps?; it is a native c# implementation of LibTiff, which I found easier to handle than a wrapper class (because there is no unmanaged memory blocks to take care of in c# app).

[Edit]Added link to TIF pyramid image documentation[/Edit]

Community
  • 1
  • 1
Adriaan
  • 3,282
  • 1
  • 23
  • 31