Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open huge TIF in .NET and copy parts to new image [closed]

I'm looking for a library that can open and copy sections of a large TIFF file. I've looked at LibTiff.Net which opens the file very quickly but it doesn't have any functions for cropping or copying sections of the image. My image is 100,000 x 100,000 pixels upwards and creating a System.Drawing.Bitmap of that size crashes the application so converting to a Bitmap first is not an option.

Can anyone recommend a .NET library?

like image 496
JWood Avatar asked Jan 25 '12 14:01

JWood


People also ask

How can I open a big TIF file?

Just install our software TIFF Viewer for Google Chrome™ To begin viewing your TIFF files, simply do the following Install the software TIFF Viewer for Google Chrome™ Click on the software icon Find the TIFF file you wish to open Its that simple, begin viewing your TIFF files online today!

Why is TIF file so big?

TIFF is uncompressed. Since TIFF does not use any compression algorithms like JPEG or GIF formats, the file contains more data and results in a more detailed picture. However, because TIFF files contain more data, the files are large and take up a lot of storage space.


2 Answers

If your file is less than 4GB on disk than I recommend you to take another look at LibTiff.Net. Even with such large images you have some options.

First of all, check whether your image is tiled or stripped. Tiff.IsTiled method will give you the answer.

If your image is tiled, than you probably shouldn't read it using ReadScanline method. It might be better to use ReadEncodedTile method in that case.

If your images is stripped, than you can use ReadScanline and ReadEncodedStrip methods to read it.

If you want to use something that expects System.Drawing.Bitmap than try using ReadRGBATile or ReadRGBAStrip. These methods can be used to create bitmaps from portions of your image. There is no sample for this, but Convert color TIFF to a 32-bit System.Drawing.Bitmap should give you almost all required information about how to convert tile or strip of an image to a bitmap.

EDIT:

LibTiff.Net 2.4.508 adds support for BigTiff so files larger than 4GB are also supported.

like image 142
Bobrovsky Avatar answered Oct 23 '22 00:10

Bobrovsky


Your image must be in BigTIFF format, since normal TIFF can't be larger than 4 GB.

BigTIFF can be read with a modified version of libtiff (available in BigTIFF website), this library allows to handle such images the way you want without loading all pixel data in memory.

I didn't see bindings for .NET but it shouldn't be too long to do it.

like image 32
CharlesB Avatar answered Oct 22 '22 23:10

CharlesB