Skip to content

Instantly share code, notes, and snippets.

@ccgus
Created July 11, 2016 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccgus/e8df08c1ab0c3643cf5010923be4885e to your computer and use it in GitHub Desktop.
Save ccgus/e8df08c1ab0c3643cf5010923be4885e to your computer and use it in GitHub Desktop.
ugh
import Cocoa
import ImageIO
import CoreGraphics
var cs = CGColorSpaceCreateDeviceRGB();
var bitmapOptions = CGBitmapInfo.byteOrder16Little.rawValue | CGImageAlphaInfo.premultipliedLast.rawValue;
var bitmapContext = CGContext(data: nil, width: 10, height: 10, bitsPerComponent: 16, bytesPerRow: 0, space: cs, bitmapInfo: bitmapOptions);
var img = bitmapContext!.makeImage();
var data = NSMutableData();
var imageDestination = CGImageDestinationCreateWithData(data, kUTTypeTIFF, 1, nil);
CGImageDestinationAddImage(imageDestination!, img!, nil);
let worked = CGImageDestinationFinalize(imageDestination!);
var imageSourceRef = CGImageSourceCreateWithData(data, nil)
var imageRef = CGImageSourceCreateImageAtIndex(imageSourceRef!, 0, NSDictionary());
imageRef!.bitsPerComponent;
assert(imageRef!.bitsPerComponent == 16)
NSLog("Done.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment