How to Apply Indenting Serialization Only to Some Properties

Using LibTiff from C# (to access tiled TIFF images)

You can try our LibTiff.Net. It is free and open source version of LibTiff written using managed C#. API of our implementation kept very similar to original one's.

https://bitmiracle.com/libtiff/

We've just released it, so there may be bugs. But full source code comes with a number of test, so most obvious bugs should be fixed.

Create a tiled Tiff using LibTiff.net

To create a tiled TIFF please don't use

output.SetField(TiffTag.ROWSPERSTRIP, output.DefaultStripSize(0));

And you absolutely must set TiffTag.TILEWIDTH and TiffTag.TILELENGTH fields before using WriteTile method.

libtiff.net split multipage tiff into single page tiff images

Yes, it's possible. TiffCP does this.

You can take TiffCP code and adapt it to your needs (change the way it stores output).

You can also come up with other ideas and implement one of those.

You might not get a complete working solution in an answer on this site.

EDIT:

Your code is mostly ok, but you should only access bytes of the memory stream after Tiff has finished writing to it.

Unfortunately, Tiff closes memory stream in it's Dispose and Close methods. You might try two approaches to overcome the issue:

  • Call Tiff.WriteDirectory before accessing bytes in the memory stream. This should be ok, but you might get an incomplete TIFF in the stream.
  • Create your own stream (based on the System.IO.MemoryStream) which overloads Close method with an empty implementation and use this stream instead of MemoryStream. Access bytes in this stream after Tiff is disposed.

Out of memory exception in reading a 1.5 GB tile-base Tiff file using LibTiff.Net

The problem is not the library not supporting BigTiff files, the error is thrown when you try to allocate a huge array. The code you wrote tries to allocate the array in the memory of your computer, expecting that there is enough space there to do so and it seems that there is not.

Handling data with sizes comparable to the available memory on the target system always requires extra attention (that's why you can see BigTiff support emphasized in the library's description).

Fortunately for you, this is not a new problem and there are solutions for this: see some answers here or here.

Basically, the idea behind these solutions is to use your hard drive (or other storage device) to store the data and provide an interface for you to swap the neccessary parts to the memory when needed (just like virtual memory).

Create Geotiff using LibTiff.Net, and add geographic information

LibTiff.Net is not able to write TiffTag.GEOTIFF_MODELTIEPOINTTAG and TiffTag.GEOTIFF_MODELPIXELSCALETAG out of the box. All the tags the library can write out of the box are listed in Tiff_DirInfo.cs file.

The SetField method returns false when you try to write unknown tag. The library also emits an error message to console.

You can teach the library how to write these GEOTIFF tags by using a code similar to one in this sample

Add custom TIFF tags to an existing TIFF image

Repacking TIFF using LibTiff.Net in Silverlight

You are supposed to use memoryStream to retrieve compressed data. Do not use tiffStream for anything in a code like this.

So, the

var retVal = new byte[tiffStream.Size(memoryStream)];
tiffStream.Read(memoryStream, retVal, 0, retVal.Length);
return retVal;

should probably be changed to

var retVal = memoryStream.ToArray();
return retVal;

Please also note that your code won't convert data so if input bytes are not 1bpp raster than the code will fail.

It's unclear why would you want to pass compressed data to the same code.



Related Topics



Leave a reply



Submit