Draw NSBitmapImageRep in NSImageView

How can I draw an NSBitmapImageRep in an NSImageView?

+4
source share
2 answers

Pretty easy:

NSImage *image = [[NSImage alloc] initWithCGImage:[bitmapRep CGImage] size:NSMakeSize(width,height)]; 

Then:

 [imageView setImage:image]; 

Another possibility is to turn it into a TIFF (- (NSData *) TIFFrepresentation) and use it to create an NSImage object, but this can lead to some overhead.

Also keep in mind that the NSBitmapImageRep - (CGImageRef) CGImage method is 10.5 or higher.

+4
source
 NSImage *im = [[[NSImage alloc] init] autorelease]; [im addRepresentation:bitmapRep]; [imageView setImage:im]; 
+13
source

Source: https://habr.com/ru/post/1339335/