Converting Tiff obect from BitMiracle LibTiff to NET types

被刻印的时光 ゝ 提交于 2019-12-13 01:49:45

问题


On client side I have image in TIFF images with multiple pages.

Firt I convert this image file to byte array and then I sent this data to web service.

For converting TIFF to byte array I use method System.IO.File.ReadAllBytes.

On web service side I would like convert this byte array to If byte array contains invalid data it will be nice to have som control.

Then I need do these things:

  • parse all pages from multi TIFF image to objects type of System.Drawing.Image

  • get specified images from multi TIFF

  • convert BitMiracle.LibTiff.Classic.Tiff object to byte array

  • save BitMiracle.LibTiff.Classic.Tiff object to disk in TIFF format

I google it, tried many samples but for me is bit problem convert byte array to BitMiracle.LibTiff.Classic.Tiff (and back) and convert BitMiracle.LibTiff.Classic.Tiffobject which hold multi TIFF to collection of System.Drawing.Image.


回答1:


There are two samples that show how to create System.Drawing.Image from a TIFF

  • Convert color TIFF to a 32-bit System.Drawing.Bitmap
  • Convert color TIFF to a 24-bit System.Drawing.Bitmap

These samples create System.Drawing.Image for the current page of a TIFF. By default, current page is the first page.

In case your TIFF image is multipage you still can use the code from samples. But you will need to encapsulate the code in a method and call that method multiple times: one time for each page.

The number of pages can be retrieved using NumberOfDirectories method. Current page can be set using SetDirectory method.

The How to use a System.IO.Stream to read or write TIFF images sample shows how to read TIFF image from a memory stream.



来源:https://stackoverflow.com/questions/12122976/converting-tiff-obect-from-bitmiracle-libtiff-to-net-types

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!