【问题标题】:Convert JPEG to Grayscale 8-bit TIFF将 JPEG 转换为灰度 8 位 TIFF
【发布时间】:2019-02-18 20:12:42
【问题描述】:

我正在尝试使用 JPEG 压缩将图像从 JPEG(彩色)转换为灰度 8 位 TIFF,但我的输出是 24 位黑白 TIFF。

我不知道如何解决这个问题:

Bitmap img = new Bitmap(oImage.FilePath);

// Set Encoder Parameters
EncoderParameters eps = new EncoderParameters(2);
eps.Param(0) = new EncoderParameter(Encoder.ColorDepth, 8L);
eps.Param(1) = new EncoderParameter(Encoder.Compression, long.Parse(((EncoderValue)(selEncoderValue.SelectedItem))));

// Set image CodecInfo
ImageCodecInfo[] ie = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo tiffEncoder = null;
for (int i = 0; (i <= (ie.Length - 1)); i++) {
    if ((ie(i).MimeType == "image/tiff")) {
        tiffEncoder = ie(i);
        break;
    }        
}

string sImageConvertedFilePath = FileExistIncrementer(string.Format("{0}\\{1}_{2}.tif", Path.GetDirectoryName(oImage.FilePath), Path.GetFileNameWithoutExtension(oImage.FileName), selEncoderValue.SelectedItem.ToString));

img.Save(sImageConvertedFilePath, tiffEncoder, eps);

这些是格式正确的图像的属性:

【问题讨论】:

    标签: c#


    【解决方案1】:

    灰色图片只不过是一堆像素,每个像素都具有相同的 R G B 颜色值。 here you have a link with the solution

    【讨论】:

    • 这个答案是错误的/不知情的。如果你的设备只能读取 8 位灰度图片,那么人眼看不到 r=g=b 的图片和真正的 8 位灰度之间的差异并不意味着机器可以使用它。跨度>
    猜你喜欢
    • 1970-01-01
    • 2013-01-06
    • 2016-10-23
    • 2021-12-16
    • 1970-01-01
    • 1970-01-01
    • 2012-03-30
    • 1970-01-01
    相关资源
    最近更新 更多