6

I got a image with only one representation, and that was a NSCGImageSnapshotRep.

I tried [NSCGImageSnapshotRep bitmapData] but, the class has no selector for bitmapData.

Someone knows this class? How can I get the bitmapData?


I'm getting this NSImage from Webkit [DOMElement renderedImage].

Create bitmap of a DOMElement Objective C

The correct use is [NSBitmapImageRep representationUsingType:id properties:id], this means doesn't work in the case.

I didn't think about compatibily, I'll be glad to find a solution 10.5+ or 10.6+.

Community
  • 1
  • 1
Ratata Tata
  • 2,781
  • 1
  • 34
  • 49
  • 1
    Do you need 10.5 compatibility, or is 10.6-only a possibility? – NSGod Dec 14 '10 at 15:06
  • NSCGImageSnapshotRep is a private subclass of NSImageRep. Unfortunately, it doesn't have the methods that a subclass of NSBitmapImageRep would. How are you creating this image, by reading it in from a file? – NSGod Dec 14 '10 at 15:16

1 Answers1

13
NSImage *img = [DOMElement renderedImage] ;
[img lockFocus] ;
NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0.0, 0.0, [img size].width, [img size].height)] ;
[img unlockFocus] ;

...

// don't forget when you are done with the rep:
[bitmapRep release] ;
qlsbjlidrfgpu
  • 146
  • 2
  • 3
  • 2
    This produces a 2x scaled image on retina displays. This answer worked for me, producing 1x images on retina displays: http://stackoverflow.com/a/24063823/105717 – Dov Dec 26 '14 at 18:30