使用MS Visual Studio创建TIFF文档 [英] create a TIFF Document using MS Visual Studio

查看:86
本文介绍了使用MS Visual Studio创建TIFF文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一些工具,可以让我创建一个TIFF文档,然后将其保存到文件夹中。如果没有内置工具,请推荐一个附加软件包。



谢谢

解决方案

.Net没有很好的工具来处理内置的TIFF格式,在工作中我们使用 LibTiff.Net [ ^ ],这是免费的开源。


< blockquote>我实际上在上周开始查看但是没有得到任何支持(我可以理解,因为它是免费的)。我希望创建一个实验室报告。在他们的一个例子中,他们建立了一座桥梁。



 使用 BitMiracle .LibTiff.Classic; 

命名空间 WriteTiff
{
class Program
{
静态 void Main( string [] args)
{
byte [] buffer = new byte [ 25 * 144 ]
{
// 无聊的十六进制
} ;


// 打开TIFF文件
使用(Tiff image = Tiff.Open( 输出.tif w))
{
if (image == null
{
System.Console.Error.WriteLine( 可以不打开output.tif写);
return ;
}

// 我们需要先为基本标签设置一些值可以添加任何数据
image.SetField(TiffTag.IMAGEWIDTH, 25 * 8 );
image.SetField(TiffTag.IMAGELENGTH, 144 );
image.SetField(TiffTag.BITSPERSAMPLE, 1 );
image.SetField(TiffTag.SAMPLESPERPIXEL, 1 );
image.SetField(TiffTag.ROWSPERSTRIP, 144 );

image.SetField(TiffTag.COMPRESSION,Compression.CCITTFAX4);
image.SetField(TiffTag.PHOTOMETRIC,Photometric.MINISWHITE);
image.SetField(TiffTag.FILLORDER,FillOrder.MSB2LSB);
image.SetField(TiffTag.PLANARCONFIG,PlanarConfig.CONTIG);

image.SetField(TiffTag.XRESOLUTION, 150 0 );
image.SetField(TiffTag.YRESOLUTION, 150 0 );
image.SetField(TiffTag.RESOLUTIONUNIT,ResUnit.INCH);

// 将信息写入文件
image。 WriteEncodedStrip( 0 ,缓冲区, 25 * 144 );

// 文件将在处理期间自动关闭
// 但您可以自己关闭图片
image.Close();
}
}
}
}







假设我想创建一个包含粗体表示Hello World的TIFF文件。你能举一个如何用LibTiff编写代码的例子吗?



谢谢。


I am looking for some tools that will allow me to create a TIFF document and then save it to a folder. If there isn''t any built in tools, please recommend an add-on package.

Thank you

解决方案

.Net does not have great tools for handling the TIFF format built in, at work we use LibTiff.Net[^], which is free and open-source.


I actually started to look t this last week but couldn''t get any support ( which I can understand since it''s free). I am looking to create a laboratory report. In one of their examples they build a bridge.

using BitMiracle.LibTiff.Classic;

namespace WriteTiff
{
    class Program
    {
        static void Main(string[] args)
        {
            byte[] buffer = new byte[25 * 144]
            {
                // boring hex omitted
            };

            // Open the TIFF file
            using (Tiff image = Tiff.Open("output.tif", "w"))
            {
                if (image == null)
                {
                    System.Console.Error.WriteLine("Could not open output.tif for writing");
                    return;
                }

                // We need to set some values for basic tags before we can add any data
                image.SetField(TiffTag.IMAGEWIDTH, 25 * 8);
                image.SetField(TiffTag.IMAGELENGTH, 144);
                image.SetField(TiffTag.BITSPERSAMPLE, 1);
                image.SetField(TiffTag.SAMPLESPERPIXEL, 1);
                image.SetField(TiffTag.ROWSPERSTRIP, 144);

                image.SetField(TiffTag.COMPRESSION, Compression.CCITTFAX4);
                image.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISWHITE);
                image.SetField(TiffTag.FILLORDER, FillOrder.MSB2LSB);
                image.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);

                image.SetField(TiffTag.XRESOLUTION, 150.0);
                image.SetField(TiffTag.YRESOLUTION, 150.0);
                image.SetField(TiffTag.RESOLUTIONUNIT, ResUnit.INCH);

                // Write the information to the file
                image.WriteEncodedStrip(0, buffer, 25 * 144);

                // file will be auto-closed during disposal
                // but you can close image yourself
                image.Close();
            }
        }
    }
}




Let''s say I want to create a TIFF file that contains says "Hello World" in bold. Can you please supply an example of how I would code this with LibTiff?

Thank you.


这篇关于使用MS Visual Studio创建TIFF文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆