Home > other >  Mac Obj - c how to screen the specified window and saved as a BMP images
Mac Obj - c how to screen the specified window and saved as a BMP images

Time:10-05

Everyone, under Windows, use the GetDC cooperate GetDIBits can get specified HWND Bitmap BGRA data, but how to operate under the Mac, I in the search engine on the key is "Mac the capture window objective - c", and many results StackOverflow about

StackOverflow suggest using Quartz Windows Services,
 CGImageRef CGWindowListCreateImage (CGRect screenBounds, 
CGWindowListOption listOption,
CGWindowID windowID,
CGWindowImageOption imageOption);

And
 NSBitmapImageRep * bitmapRep=[[NSBitmapImageRep alloc] initWithCGImage: screenShot]; 
Init NSImage * image=[[NSImage alloc]].
[image addRepresentation: bitmapRep];
[bitmapRep release];
BitmapRep=nil;


But CGWindowID Xcode found out I was actually uint32_t, however now MacOSX are no 32 bit, I use the QT demo QWidget winID () is a 64 - bit, numerical more than 2 * * 32-1, if using the above function, preach the past will be truncated,

Now the goal is, assuming A QT program A, his window ID is X, and then write A OC code, to capture images of the X window content, get A native RGBA data saved to A buffer, I had to write c + +, OC are not familiar with, don't know whether this buffer type NSArray, but I know that can be converted to an unsigned char * buffer,

Would you please tell me what the code sample, or you have any idea about advice, the best is the sample code, because I am really not familiar with the OC,
  • Related