1

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

alwaysVBNET
  • 3,150
  • 8
  • 32
  • 65

1 Answers1

-1

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

  • This answer is wrong/uninformed. If you have a device that is only capable of reading 8 bit grayscale pictures, the fact that the human eye cant see a difference between r=g=b pictures and a true 8bit grayscale doesnt mean the machine is able to use it. – Flocke Mar 19 '21 at 09:41