本文介绍了需要C#函数为灰度TIFF转换为黑色&安培;白(单色/ 1BPP)TIFF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将一个byte [] 8位灰度TIFF,并返回一个byte [] 1位(黑白与白)的C#函数。TIFF



我是相当新的与TIFF格式的工作,但总的想法是,我们需要把它们从灰度或彩色转换为黑白/黑白/二​​进制图像格式。



我们收到通过WCF的图像作为一个byte [],那么我们就需要进行这种转换为黑色&安培;白,以便将它们发送到哪个做进一步处理的组分。我们并不在这一点计划,永远将其保存为文件



有关参考,在我们的测试客户端,这是我们如何创建字节[]:

 的FileStream FS =新的FileStream(test1.tif,FileMode.Open,FileAccess.Read); 
this.image =新的字节[fs.Length]
fs.Read(this.image,0,System.Convert.ToInt32(fs.Length));
fs.Close();



-------- ---------更新



我觉得这里可能有超过1个很好的答案,但我们最终使用的代码从CodeProject上网站用以下方法添加到重载转换函数接受字节]以及位图:

 公共静态字节] ConvertToBitonal(字节[]原创)
{
位图BM =新位图(新System.IO.MemoryStream(原件,FALSE));
BM = ConvertToBitonal(BM);
System.IO.MemoryStream S =新System.IO.MemoryStream();
bm.Save(S,System.Drawing.Imaging.ImageFormat.Tiff);
返回s.ToArray();
}


解决方案

在CodeProject上的一篇文章的rel=\"nofollow\">描述你所需要的。


I need a C# function that will take a Byte[] of an 8 bit grayscale TIFF, and return a Byte[] of a 1 bit (black & white) TIFF.

I'm fairly new to working with TIFFs, but the general idea is that we need to convert them from grayscale or color to black and white/monochrome/binary image format.

We receive the images via a WCF as a Byte[], then we need to make this conversion to black & white in order to send them to a component which does further processing. We do not plan at this point, to ever save them as files.

For reference, in our test client, this is how we create the Byte[]:

        FileStream fs = new FileStream("test1.tif", FileMode.Open, FileAccess.Read);
        this.image = new byte[fs.Length];
        fs.Read(this.image, 0, System.Convert.ToInt32(fs.Length));
        fs.Close();

--------update---------

I think there may be more than 1 good answer here, but we ended up using the code from the CodeProject site with the following method added to overload the convert function to accept Byte[] as well as bitmap:

public static Byte[] ConvertToBitonal(Byte[] original)
    {
        Bitmap bm = new Bitmap(new System.IO.MemoryStream(original, false));
        bm = ConvertToBitonal(bm);
        System.IO.MemoryStream s = new System.IO.MemoryStream();
        bm.Save(s, System.Drawing.Imaging.ImageFormat.Tiff);
        return s.ToArray();
    }
解决方案

There is an article on CodeProject here that describes what you need.

这篇关于需要C#函数为灰度TIFF转换为黑色&安培;白(单色/ 1BPP)TIFF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 21:40