Skip to content

Instantly share code, notes, and snippets.

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

What would you like to do?
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());
assert(imageRef!.bitsPerComponent == 16)
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.