Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > fastest way to dump an image to a view

fastest way to dump an image to a view
Thread Tools
arcticmac
Dedicated MacNNer
Join Date: Apr 2004
Status: Offline
Reply With Quote
Dec 9, 2006, 12:53 PM
 
If I'm drawing a lot of images, what's the fastest thing for me to use?
I've looked at
[NSImage drawAtPoint: fromRect: operation: fraction:];
[NSImage compositeToPoint: fromRect: operation: fraction:];
[NSImage compositeToPoint: fromRect: operation:];
and I'm also considering
CGContextDrawImage(context, imageRect, image);
(FYI, the images are, generally speaking, transparent in places, and I do need to have the image clipped);

Which one of these is fastest (or feel free to suggest another way if you can think of one)?

Edit:
I tested the three NSImage methods, and was surprised to find that drawAtPoint: seemed to be fastest, followed by compositeToPoint:fromRect:operation:, then compositeToPoint:fromRect:operation:fraction. I'd kinda expected that the first two would both call compositeToPoint:fromRect:operation:fraction: to do their drawing anyway and thus be slower, but I guess not.

Also, my testing suggests that for the NSImages, NSCompositeCopy is faster than NSCompositeSourceOver... is this correct?
     
Catfish_Man
Mac Elite
Join Date: Aug 2001
Status: Offline
Reply With Quote
Dec 9, 2006, 02:08 PM
 
If you're drawing the same image multiple times, you might consider CGLayer as well. Quartz 2D Programming Guide: CGLayer Drawing

Be sure to investigate getRectsNeedingDisplay to minimize redrawing, and use Shark heavily to avoid unforeseen bottlenecks.
     
arcticmac  (op)
Dedicated MacNNer
Join Date: Apr 2004
Status: Offline
Reply With Quote
Dec 9, 2006, 02:36 PM
 
mmm... I might think about that, although I'm not sure in this particular case it'll make sense... however, there's some more drawing that I'll hopefully get to later in this project that WOULD be excellent for CGLayer I think.

Thanks

I will maybe work more on getRectsNeedingDisplay and using Shark more once I get the app to compile (I've been doing some very major reworking, and I haven't had it in a state where it actually compiles properly in like 3 weeks - I don't get a lot of time for coding)

oh, and PS.
I tried out all the drawing methods I listed above for speed, and when I was drawing the whole image, [NSImage drawAtPoint:fromRect:operation:fraction:] was fastest, but when I clip it to a particular rect, CGContextDrawImage is the fastest. (although, maybe I was doing something wrong. when I tried to clip the image, [NSImage drawAtPoint:fromRect:operation:fraction:] insisted on scaling the region I wanted to draw up so it was the size of the whole image.)
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Dec 9, 2006, 05:00 PM
 
By the way, I don't know if you've tried it with transparent images yet, but I think NSCompositeCopy is faster than other drawing methods because it ignores opacity — it just copies in the whole image, including parts that should be transparent.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
arcticmac  (op)
Dedicated MacNNer
Join Date: Apr 2004
Status: Offline
Reply With Quote
Dec 10, 2006, 09:20 PM
 
NSCompositeCopy copies the whole image, including transparency, which is actually fine for me because I'm not drawing on top of anything that I care about. I just need the image.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 03:47 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,