0
votes

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:

enter image description here

1

1 Answers

-1
votes

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