, 당신이 8 비트에서 이미지 데이터를 변환하는 표시 1 비트 바르게. 그럴 경우 자신의 코드를 사용하여 처음부터 다시 할 특별한 이유가 없으면 System.Drawing.Bitmap 및 System.Drawing.Imaging.ImageCodecInfo를 사용하여 유효한 TIFF 파일을 만드는 작업을 단순화 할 수 있습니다. 압축되지 않은 1 비트 TIFF 또는 압축 유형이 다른 압축 파일을 저장할 수 있습니다. 코드는 다음과 같습니다.
// first convert from byte[] to pointer
IntPtr pData = Marshal.AllocHGlobal(imgData.Length);
Marshal.Copy(imgData, 0, pData, imgData.Length);
int bytesPerLine = (imgWidth + 31)/32 * 4; //stride must be a multiple of 4. Make sure the byte array already has enough padding for each scan line if needed
System.Drawing.Bitmap img = new Bitmap(imgWidth, imgHeight, bytesPerLine, PixelFormat.Format1bppIndexed, pData);
ImageCodecInfo TiffCodec = null;
foreach (ImageCodecInfo codec in ImageCodecInfo.GetImageEncoders())
if (codec.MimeType == "image/tiff")
{
TiffCodec = codec;
break;
}
EncoderParameters parameters = new EncoderParameters(2);
parameters.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionLZW);
parameters.Param[1] = new EncoderParameter(Encoder.ColorDepth, (long)1);
img.Save("OnebitLzw.tif", TiffCodec, parameters);
parameters.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
img.Save("OnebitFaxGroup4.tif", TiffCodec, parameters);
parameters.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionNone);
img.Save("OnebitUncompressed.tif", TiffCodec, parameters);
img.Dispose();
Marshal.FreeHGlobal(pData); //important to not get memory leaks
Photoshop은 동일한 단계를 수행 할 때 생성됩니다. – Joey
Spec : https://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf –
잘못된 BITSPERSAMPLE 및/또는 SAMPLESPERPIXEL 값을 잘못 지정했을 수 있습니다. AsTiffTagViewer 유틸리티를 사용하여 이미지를 열어보고 표시되는 내용을 확인하십시오. – Bobrovsky