Advertisement
Guest User

Untitled

a guest
Sep 13th, 2013
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. CGDataProviderRef provider= CGDataProviderCreateWithData(NULL (UInt8*)data, bytesPerRow * length, NULL);
  2. CGImageRef cgImg = CGImageCreate (
  3. width,
  4. length,
  5. bitsPerComponent,
  6. bitsPerPixel,
  7. bytesPerRow,
  8. colorspace,
  9. bitmapinfo, // ? CGBitmapInfo bitmapInfo,
  10. provider, //? CGDataProviderRef provider,
  11. NULL, //const CGFloat decode[],
  12. true, //bool shouldInterpolate,
  13. kCGRenderingIntentDefault // CGColorRenderingIntent intent
  14. );
  15. /* CGColorSpaceRelease(colorspace); */
  16.  
  17. NSData* imgData = [NSMutableData data];
  18. CGImageDestinationRef dest = CGImageDestinationCreateWithData
  19. (imgData, kUTTypeTIFF, 1, NULL);
  20. CGImageDestinationAddImage(dest, cgImg, NULL);
  21. CGImageDestinationFinalize(dest);
  22. NSImage* img = [[NSImage alloc] initWithData: imgData];
  23.  
  24. NSData * byteData = [NSData dataWithBytes:data length:length];
  25. NSBitmapImageRep * imageRep = [NSBitmapImageRep imageRepWithData:byteData];
  26. NSSize imageSize = NSMakeSize(CGImageGetWidth([imageRep CGImage]), CGImageGetHeight([imageRep CGImage]));
  27.  
  28. NSImage * image = [[NSImage alloc] initWithSize:imageSize];
  29. [image addRepresentation:imageRep];
  30.  
  31. ...use image
  32.  
  33. size_t bufferLength = width * height * 4;
  34. CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, data, bufferLength, NULL);
  35. size_t bitsPerComponent = 8;
  36. size_t bitsPerPixel = 32;
  37. size_t bytesPerRow = 4 * width;
  38. CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
  39. CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast;
  40. CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
  41.  
  42. CGImageRef iref = CGImageCreate(width,
  43. height,
  44. bitsPerComponent,
  45. bitsPerPixel,
  46. bytesPerRow,
  47. colorSpaceRef,
  48. bitmapInfo,
  49. provider, // data provider
  50. NULL, // decode
  51. YES, // should interpolate
  52. renderingIntent);
  53.  
  54. _image = [[NSImage alloc] initWithCGImage:iref size:NSMakeSize(width, height)];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement