NSCGImageSnapshotRep,如何获取bitmapData

Rat*_*ata 6 cocoa objective-c

我得到的图像只有一个表示,那是一个NSCGImageSnapshotRep.

我试过[NSCGImageSnapshotRep bitmapData]但是,班级没有选择器bitmapData.

有人知道这堂课吗?我该bitmapData怎么办?


我从Webkit获得了这个NSImage [DOMElement renderedImage].

创建DOMElement Objective C的位图

正确的用法是[NSBitmapImageRep representationUsingType:id properties:id],这种方法在这种情况下不起作用.

我也没多想compatibily,我会很高兴找到一个解决方案10.5+10.6以上版本.

小智 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] ;
Run Code Online (Sandbox Code Playgroud)

  • 这会在视网膜显示器上生成 2 倍缩放的图像。这个答案对我有用,在视网膜显示器上生成 1x 图像:http://stackoverflow.com/a/24063823/105717 (2认同)