Hi,

I have a Mac app that loads a Leaflet.js map into a web view.

I've written a screenshot method to grab the map for inclusion in a print view. 
This is largely based on the examples here:

http://stackoverflow.com/questions/11948241/cocoa-how-to-render-view-to-image

I'm writing my app on 10.8 and targeting 10.7 and above.

I've tried the three methods shown in the SO post, and only the 
CGWindowListCreateImage works correctly in my app.

The problem I have is that the quality of the resultant image is poor, which is 
exacerbated when the image is resized for printing.

By comparison, if I run my app, display the map, and then take a screenshot 
with Realmac's Littlesnapper app, the resultant image is of a much higher 
quality, and looks good on screen and printed. This isn't resized though, so 
not a direct comparison.

Can anyone suggest an alternative approach for grabbing screenshots? I've spent 
a lot of time Googling for tips, and trying out different code snippets, but 
nothing has dramatically improved the image quality.

For reference, what I am doing is essentially:

1. Work out the rect of the map view

2. Call CGWindowListCreateImage

    CGImageRef cgimg = CGWindowListCreateImage(rect,
                                               
kCGWindowListOptionIncludingWindow,
                                               (CGWindowID)[[aView window] 
windowNumber],
                                               kCGWindowImageDefault);

3. Create an NSImage:

    return [[[NSImage alloc] initWithCGImage:cgimg size:[aView bounds].size] 
autorelease];

4. Add the image to the print view.


I tried dataWithPDFInsideRect: and bitmapImageRepForCachingDisplayInRect: but 
both produced blank screenshots.

Thanks

Darren.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to