将 Tiff 对象从 BitMiracle LibTiff 转换为 NET 类型 [英] Converting Tiff obect from BitMiracle LibTiff to NET types
问题描述
在客户端,我有包含多页的 TIFF 图像中的图像.
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.
为了将 TIFF 转换为字节数组,我使用方法 System.IO.File.ReadAllBytes
.
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:
将所有页面从多 TIFF 图像解析为
System.Drawing.Image
从多个 TIFF 中获取指定图像
get specified images from multi TIFF
将 BitMiracle.LibTiff.Classic.Tiff
对象转换为字节数组
convert BitMiracle.LibTiff.Classic.Tiff
object to byte array
将 BitMiracle.LibTiff.Classic.Tiff
对象以 TIFF 格式保存到磁盘
save BitMiracle.LibTiff.Classic.Tiff
object to disk in TIFF format
我谷歌它,尝试了很多样本,但对我来说有点问题将字节数组转换为BitMiracle.LibTiff.Classic.Tiff
(并返回)并将包含多个 TIFF 的 BitMiracle.LibTiff.Classic.Tiff
对象转换为System.Drawing.Image
.
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.Tiff
object which hold multi TIFF to
collection of System.Drawing.Image
.
推荐答案
有两个示例展示了如何从 TIFF 创建 System.Drawing.Image
There are two samples that show how to create System.Drawing.Image
from a TIFF
这些示例为 TIFF 的当前页面创建了System.Drawing.Image
.默认情况下,当前页面为第一页.
These samples create System.Drawing.Image
for the current page of a TIFF. By default, current page is the first page.
如果您的 TIFF 图像是多页的,您仍然可以使用示例中的代码.但是您需要将代码封装在一个方法中并多次调用该方法:每个页面一次.
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.
可以使用NumberOfDirectories 方法.可以使用 SetDirectory<设置当前页面/a> 方法.
The number of pages can be retrieved using NumberOfDirectories method. Current page can be set using SetDirectory method.
如何使用 System.IO.Stream 读取或写入 TIFF 图像 示例展示了如何从内存流中读取 TIFF 图像.
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.
这篇关于将 Tiff 对象从 BitMiracle LibTiff 转换为 NET 类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!