Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This seems to work and produce not-all-black output. There may be a way to do it that doesn't involve a manual conversion to grayscale first, but at least it works!</p> <pre><code>static void WriteCCITTTiffWithCGImage_URL_(CGImageRef im, CFURLRef url) { // produce grayscale image CGImageRef grayscaleImage; { CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericGray); CGContextRef bitmapCtx = CGBitmapContextCreate(NULL, CGImageGetWidth(im), CGImageGetHeight(im), 8, 0, colorSpace, kCGImageAlphaNone); CGContextDrawImage(bitmapCtx, CGRectMake(0,0,CGImageGetWidth(im), CGImageGetHeight(im)), im); grayscaleImage = CGBitmapContextCreateImage(bitmapCtx); CFRelease(bitmapCtx); CFRelease(colorSpace); } // generate options for ImageIO. Man this sucks in C. CFMutableDictionaryRef options = CFDictionaryCreateMutable(kCFAllocatorDefault, 2, &amp;kCFTypeDictionaryKeyCallBacks, &amp;kCFTypeDictionaryValueCallBacks); { { CFMutableDictionaryRef tiffOptions = CFDictionaryCreateMutable(kCFAllocatorDefault, 1, &amp;kCFTypeDictionaryKeyCallBacks, &amp;kCFTypeDictionaryValueCallBacks); int fourInt = 4; CFNumberRef fourNumber = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &amp;fourInt); CFDictionarySetValue(tiffOptions, kCGImagePropertyTIFFCompression, fourNumber); CFRelease(fourNumber); CFDictionarySetValue(options, kCGImagePropertyTIFFDictionary, tiffOptions); CFRelease(tiffOptions); } { int oneInt = 1; CFNumberRef oneNumber = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &amp;oneInt); CFDictionarySetValue(options, kCGImagePropertyDepth, oneNumber); CFRelease(oneNumber); } } // write file CGImageDestinationRef idst = CGImageDestinationCreateWithURL(url, kUTTypeTIFF, 1, NULL); CGImageDestinationAddImage(idst, grayscaleImage, options); CGImageDestinationFinalize(idst); // clean up CFRelease(idst); CFRelease(options); CFRelease(grayscaleImage); } Nepheli:tmp ken$ tiffutil -info /tmp/output.tiff Directory at 0x1200 Image Width: 842 Image Length: 562 Bits/Sample: 1 Sample Format: unsigned integer Compression Scheme: CCITT Group 4 facsimile encoding Photometric Interpretation: "min-is-black" Orientation: row 0 top, col 0 lhs Samples/Pixel: 1 Number of Strips: 1 Planar Configuration: Not planar </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload