code:- (char *)getframebuffer { cgimageref imageref = cgdisplaycreateimage(displayid); if(imageref == null) return null; cgcontextref context = [size="3"][color="red"]createargbbitmapcontext[/color][/size](imageref ); if(context == null) return null; size_t w = cgimagegetwidth(imageref ); size_t h = cgimagegetheight(imageref); cgrect rect = {{0,0},{w,h}}; rfblog("111"); cgcontextdrawimage(context, rect,imageref ); rfblog("222"); char *returnvalue = (char *)cgbitmapcontextgetdata(context); return returnvalue; } /////////////////////////////////////////////// cgcontexref createargbbitmapcontext(cgimageref inimage) { int bitmapbytesperrow; int bitmapbytecount; cgcolorspaceref colorspace; char *bitmapdata; cgcontextref context = null; size_t pixelswidth = cgimagegetwidth(inimage); size_t pixelsheight = cgimagegetheight(inimage); bitmapbytesperrow = pixelswidth * 4; bitmapbytecount = bitmapbytesperrow * pixelsheight ; colorspace = cgcolorspacecreatewithname(kcgcolorspacegenericrgb); if(colorspace == null ) return null; bitmapdata = (char *)malloc(sizeof(char ) * bitmapbytecount ); if(bitmapdata== null ) { cgcolorspacerelease(colorspace); return null; } context = cgbitmapcontextcreate(bitmapdata, pixelswidth , pixelsheight, 8, bitmapbytesperrow , colorspace , kcgimagealphapremultipliedlast); if(context == null) free(bitmapdata); cgcolorspacerelease(colorspace); return context; }
code error "cgimagedatalock : cannot allocate memory" after printing "111".
spent time on still don't find reason。
thks!!!
what trying image?
Forums Macs Mac Programming
- iPhone
- Mac OS & System Software
- iPad
- Apple Watch
- Notebooks
- iTunes
- Apple ID
- iCloud
- Desktop Computers
- Apple Music
- Professional Applications
- iPod
- iWork
- Apple TV
- iLife
- Wireless
No comments:
Post a Comment