简体   繁体   中英

Convert JPEG to Grayscale 8-bit TIFF

I am trying to convert images from JPEG (with color) to grayscale 8-bit TIFF with JPEG compression but my output is a 24-bit black and white TIFF.

I'm not sure how to tackle this:

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);

These are the properties of a correctly formatted image:

在此处输入图片说明

gray picture is nothing else but a bunch of pixels with each pixel the having the same RGB color value. here you have a link with the solution

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM