Skip to content

Instantly share code, notes, and snippets.

@ccgus ccgus/what.swift
Created Jul 11, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.