我想了解并实现Tiff压缩的一段代码。 (第一种方法体积庞大)和图像保存方法http://msdn.microsoft.com/en-us/library/ytz20d80%28v=vs.110%29.aspx(第二种方法仅适用于Windows 7计算机,但不适用于Windows 2003或2008服务器)我已经使用了2种独立技术 - 使用第三方dll的LibTiff.NEt(第一种方法很笨重)和图像保存方法,http://msdn.microsoft.com/en-us/library/ytz20d80%28v=vs.110%29.aspx 。c#Tiff文件压缩方法
现在我正在寻找探索这第三种方法。
using System.Windows.Forms;
using System.Windows.Media.Imaging;
using System.Drawing.Imaging;
int width = 800;
int height = 1000;
int stride = width/8;
byte[] pixels = new byte[height*stride];
// Try creating a new image with a custom palette.
List<System.Windows.Media.Color> colors = new List<System.Windows.Media.Color>();
colors.Add(System.Windows.Media.Colors.Red);
colors.Add(System.Windows.Media.Colors.Blue);
colors.Add(System.Windows.Media.Colors.Green);
BitmapPalette myPalette = new BitmapPalette(colors);
// Creates a new empty image with the pre-defined palette
BitmapSource image = BitmapSource.Create(
width,
height,
96,
96,
System.Windows.Media.PixelFormats.BlackWhite,
myPalette,
pixels,
stride);
FileStream stream = new FileStream(Original_File, FileMode.Create);
TiffBitmapEncoder encoder = new TiffBitmapEncoder();
encoder.Compression = TiffCompressOption.Ccitt4;
encoder.Frames.Add(BitmapFrame.Create(image));
encoder.Save(stream);
但我没有对这里发生的事情有充分的了解。
显然有一种类型的压缩技术正在应用的内存流。但我有点困惑如何将这个应用到我的具体情况。我有一个原始的tiff文件,我想使用此方法将其压缩设置为CCITT并将其保存。谁能帮忙?
我复制了上面的代码并运行代码。但我的最终输出文件是纯黑色背景图像。虽然积极的一面是正确的压缩类型。
http://msdn.microsoft.com/en-us/library/ms616002%28v=vs.110%29.aspx
你为什么添加asp.net标签?你在做这个是一个asp.net项目吗? – mbeckish
是的。我有一个网页,允许用户输入,然后转换成一个tiff文件。这个tiff文件的原始压缩类型是LZW。我需要CCITT压缩格式。 – Philo
您可能会遇到问题,因为[ASP.NET服务中不支持图形命名空间](http://stackoverflow.com/q/390532/21727) – mbeckish