For the critical parts that is the same code as posted. Any other ideas?
Was this code operational on any PDF? Or by any chance just against PDFs where the streams in question contained raw pixels from Bitmaps that were Format1BppIndexed?
The reason I asked is the following code produces the correct image using the same concept only against libtiff using raw format and not C# Bitmap class. So I'm wondering if this is a problem with Bitmaps and Format1BppIndexed not supporing this operation?
Code:
byte[] pixels = xobject.Stream.Value;
int tif = TIFFOpen("c:\\example.tif", "w");
TIFFSetField(tif, (uint)BitMiracle.LibTiff.Classic.TiffTag.IMAGEWIDTH, (uint)width);
TIFFSetField(tif, (uint)BitMiracle.LibTiff.Classic.TiffTag.IMAGEHEIGHT, (uint)height);
TIFFSetField(tif, (uint)BitMiracle.LibTiff.Classic.TiffTag.COMPRESSION,
(uint)BitMiracle.LibTiff.Classic.Compression.NONE);
TIFFSetField(tif, (uint)BitMiracle.LibTiff.Classic.TiffTag.PHOTOMETRIC
(uint)BitMiracle.LibTiff.Classic.Photometric.MINISWHITE);
TIFFSetField(tif, (uint)BitMiracle.LibTiff.Classic.TiffTag.BITSPERSAMPLE,
(uint)bitsPerComponent);
TIFFSetField(tif, (uint)BitMiracle.LibTiff.Classic.TiffTag.SAMPLESPERPIXEL, 1);
IntPtr pointer = Marshal.AllocHGlobal(pixels.length);
Marshal.Copy(pixels, 0, pointer, pixels.length);
TIFFWriteRawStrip(tif, 0, pointer, pixels.length);
TIFFClose(tif);
Again I'm new to this but here are the tags for the stream in question. And there is no /Filter tag so this is just raw pixels right? 1 bit per pixel inverting black and white?
<</Type/XObject
/Subtype/Image
/Width 2344
/Height 1654
/BitsPerComponent 1
/ColorSpace/DeviceGray
/Decode[1 0]
/Length 484622