• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Capturing the Content of a IKImageBrowserView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Capturing the Content of a IKImageBrowserView


  • Subject: Re: Capturing the Content of a IKImageBrowserView
  • From: Anthony Mittaz <email@hidden>
  • Date: Thu, 10 Jan 2008 14:03:50 +1000

Thanks this works well except that when I'm using this code the resulting image has no shadow under each browser item.

Is there anything i can add to this code the get back my shadows ;-)

Here You can see the original IKImageBrowser and the resulting image.

http://web.mac.com/sync/Site/IKImageBrowserViewProblem.html


On 10/01/2008, at 2:24 AM, Thomas Goossens wrote:

Hello Anthony,

This is because the IKImageBrowserView renders itself into an openGL surface.
So you can't retrieve the pixels using the usual AppKit code path.


But instead you can try this:

//1) allocate a c buffer at the size of the visible rect of the image browser
NSRect vRect = [yourImageBrowserView visibleRect];
NSSize size = vRect.size;

void *buffer = malloc(size.width * size.height * 4);


//2) read the pixels using openGL
[yourImageBrowserView lockFocus];
glReadPixels(0,
             0,
             size.width,
             size.height,
             GL_RGBA,
             GL_UNSIGNED_BYTE,
             buffer);
[yourImageBrowserView unlockFocus];

//3) create a bitmap with those pixels
unsigned char *planes[2];
planes[0] = (unsigned char *) (buffer);

NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:planes pixelsWide:size.width pixelsHigh:size.height bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace bitmapFormat:0 bytesPerRow:size.width*4 bitsPerPixel:32];

//4) create a temporary image with this bitmap and set it flipped (because openGL and the AppKit don't have the same pixels coordinate system)
NSImage *img = [[NSImage alloc] initWithSize:size];
[img addRepresentation:imageRep];
[img setFlipped:YES];
[imageRep release];

//5) draw this temporary image into another image so that we get an image without any reference to our "buffer" buffer so that we can release it after that
NSImage *finalImage = [[NSImage alloc] initWithSize:size];
[finalImage lockFocus];
[img drawAtPoint:NSZeroPoint fromRect:NSMakeRect(0,0,size.width,size.height) operation:NSCompositeCopy fraction:1.0];
[finalImage unlockFocus];

//6) release intermediate objects
[img release];
free(buffer);


-- Thomas.


On Jan 9, 2008, at 5:00 PM, Anthony Mittaz wrote:

Hello,

I'm currently trying to capture the content of a IkImageBrowserView but the image resulting from this operation is always blank.

My code:

[MyIkImageBrowserView lockFocus];
NSBitmapImageRep *imageRep = [MyIkImageBrowserView bitmapImageRepForCachingDisplayInRect:[MyIkImageBrowserView frame]];
[MyIkImageBrowserView cacheDisplayInRect:[MyIkImageBrowserView frame] toBitmapImageRep:imageRep];
[MyIkImageBrowserView unlockFocus];


NSImage *image = [[NSImage alloc] initWithSize:sizeOfMyIkImageBrowserView];
[image addRepresentation:imageRep];


[imageViewOfTheView setImage:image];

If someone could give me a better solution i would be more than happy.

Thanks
Anthony Mittaz
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Capturing the Content of a IKImageBrowserView
      • From: Thomas Goossens <email@hidden>
References: 
 >Capturing the Content of a IKImageBrowserView (From: Anthony Mittaz <email@hidden>)
 >Re: Capturing the Content of a IKImageBrowserView (From: Thomas Goossens <email@hidden>)

  • Prev by Date: Property List Serialization in Sketch
  • Next by Date: Re: Property List Serialization in Sketch
  • Previous by thread: Re: Capturing the Content of a IKImageBrowserView
  • Next by thread: Re: Capturing the Content of a IKImageBrowserView
  • Index(es):
    • Date
    • Thread