convert CGImageRef to picHandle

External developers... This forum's for you!

convert CGImageRef to picHandle

Postby mrBean » Wed Mar 30, 2011 3:29 pm

I'm using CGWindowListCreateImageFromArray to take a snap shot of selected windows. I would like to take this image and set the pictureData of a graphic. the problem is that i can't figure out how to convert a CGImageRef to a PicHandle. if anybody has any idea on how to do this, it be a big help.

--sean
User avatar
mrBean
 
Posts: 89
Joined: Sat Jan 30, 2010 8:03 am
Location: New York

Re: convert CGImageRef to picHandle

Postby codegreen » Wed Mar 30, 2011 7:34 pm

mrBean wrote:I'm using CGWindowListCreateImageFromArray to take a snap shot of selected windows. I would like to take this image and set the pictureData of a graphic. the problem is that i can't figure out how to convert a CGImageRef to a PicHandle. if anybody has any idea on how to do this, it be a big help.

This is off the top of my head and totally untested, but it (or something close to it) might work:

Code: Select all
Boolean CGImageRefToPICT(CGImageRef ref, PicHandle *hPic)
{
   CGImageDestinationRef dest;
   CFMutableDataRef data;
   Boolean success = false;
   Handle h = nil;
   Size len;
   
   if ((data = CFDataCreateMutable(NULL, 0))) {
      if ((dest = CGImageDestinationCreateWithData(data, kUTTypePICT, 1, NULL))) {
         CGImageDestinationAddImage(dest, ref, NULL);
         success = CGImageDestinationFinalize(dest);
         CFRelease(dest);
         if (success) {
            if ((h = NewHandle(len = CFDataGetLength(data))))
               CFDataGetBytes(data, CFRangeMake(0, len), (UInt8 *)*h);
             else success = false;
         }
      }
      CFRelease(data);
   }
   *hPic = (PicHandle)h;
   return success;
}

HTH,
-Mark
codegreen
 
Posts: 1510
Joined: Mon Jul 14, 2008 11:03 pm

Re: convert CGImageRef to picHandle

Postby mrBean » Sat Apr 02, 2011 3:09 pm

thanks mark for your help.
User avatar
mrBean
 
Posts: 89
Joined: Sat Jan 30, 2010 8:03 am
Location: New York


Return to Xcode and the Internals Toolbox

Who is online

Users browsing this forum: No registered users and 1 guest

cron