2014-11-14 7 views
0

8bit TIFF를 1bit로 변환하지만 출력 파일을 Photoshop (또는 다른 그래픽 소프트웨어)에서 열 수없는 데스크탑 응용 프로그램을 작성했습니다. 어떤 어플리케이션 일은 TIFF를 1bit로 변환

  • 이 모든 8 바이트의 원 화상의 (픽셀 당 1 바이트) 다음 bool에 각 값 변환
  • 은 (따라서 0 또는 1)
  • 마다 8 개 화소 절약을 반복 할 것이다 바이트 - 다른 바이트의 비트는 원래 이미지

I가 세트 TIFF 태그의 화소와 동일한 순서이다 : MINISBLACK 압축 없음없고, 평면 구성은 연속적이며, 순서 MSB2LSB 채우. BitMiracle의 LibTiff.NET을 사용하여 파일을 읽고 쓰고 있습니다.

인기있는 소프트웨어로 출력을 열 수 없다는 점을 내가 잘못하고 있습니까?

입력 이미지 : http://www.filedropper.com/input
출력 이미지 : http://www.filedropper.com/output
내 변환 코드 : http://paste.ofcode.org/jqQ4zQp5SYaJwR2rUybBa 바이트 조작부의 당신의 묘사에서

+1

Photoshop은 동일한 단계를 수행 할 때 생성됩니다. – Joey

+0

Spec : https://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf –

+0

잘못된 BITSPERSAMPLE 및/또는 SAMPLESPERPIXEL 값을 잘못 지정했을 수 있습니다. AsTiffTagViewer 유틸리티를 사용하여 이미지를 열어보고 표시되는 내용을 확인하십시오. – Bobrovsky

답변

0

, 당신이 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 
+0

지금 다른 프로젝트를 진행하고 있지만이 문제가 다시 발생하면 해결 방법을 시도해 보겠습니다. – Val