Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CGDataProviderRef provider= CGDataProviderCreateWithData(NULL (UInt8*)data, bytesPerRow * length, NULL);
- CGImageRef cgImg = CGImageCreate (
- width,
- length,
- bitsPerComponent,
- bitsPerPixel,
- bytesPerRow,
- colorspace,
- bitmapinfo, // ? CGBitmapInfo bitmapInfo,
- provider, //? CGDataProviderRef provider,
- NULL, //const CGFloat decode[],
- true, //bool shouldInterpolate,
- kCGRenderingIntentDefault // CGColorRenderingIntent intent
- );
- /* CGColorSpaceRelease(colorspace); */
- NSData* imgData = [NSMutableData data];
- CGImageDestinationRef dest = CGImageDestinationCreateWithData
- (imgData, kUTTypeTIFF, 1, NULL);
- CGImageDestinationAddImage(dest, cgImg, NULL);
- CGImageDestinationFinalize(dest);
- NSImage* img = [[NSImage alloc] initWithData: imgData];
- NSData * byteData = [NSData dataWithBytes:data length:length];
- NSBitmapImageRep * imageRep = [NSBitmapImageRep imageRepWithData:byteData];
- NSSize imageSize = NSMakeSize(CGImageGetWidth([imageRep CGImage]), CGImageGetHeight([imageRep CGImage]));
- NSImage * image = [[NSImage alloc] initWithSize:imageSize];
- [image addRepresentation:imageRep];
- ...use image
- size_t bufferLength = width * height * 4;
- CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, data, bufferLength, NULL);
- size_t bitsPerComponent = 8;
- size_t bitsPerPixel = 32;
- size_t bytesPerRow = 4 * width;
- CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
- CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast;
- CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
- CGImageRef iref = CGImageCreate(width,
- height,
- bitsPerComponent,
- bitsPerPixel,
- bytesPerRow,
- colorSpaceRef,
- bitmapInfo,
- provider, // data provider
- NULL, // decode
- YES, // should interpolate
- renderingIntent);
- _image = [[NSImage alloc] initWithCGImage:iref size:NSMakeSize(width, height)];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement