Re: NSImage from bitmap - then delete bitmap
Re: NSImage from bitmap - then delete bitmap
- Subject: Re: NSImage from bitmap - then delete bitmap
- From: Trygve Inda <email@hidden>
- Date: Thu, 21 Jul 2016 23:40:50 -0700
- Thread-topic: NSImage from bitmap - then delete bitmap
> With half an eye on performance, if you *do* strictly need a copy of the
> bitmap, note that NSBitmapImageRep conforms to NSCopying. You don’t have to
> turn it into a TIFF and back again.
>
> Also, you don’t even need an NSImage - the NSImageRep can be drawn directly.
A little deeper discussion of how my app works.
I have a background worker thread whose purpose is to generate a continuous
series of NSImages - from one per second to one every 5 minutes or so). I
may have several of these worker threads working on different images.
The thread starts by making a pixel buffer using:
[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL ......
Then the thread goes into a loop where on each pass it draws the correct
image into this pixel buffer.
After the image is drawn it need to be handed off to the main thread to be
drawn into a window.
As soon as it is handed off, the thread starts drawing a new image,
destroying the pixels used to create the image that was just handed off.
It is likely that the image will not be received by the main thread and
drawn into the window before the pixels in the NSBitmapImageRep are
destroyed (because it the thread is now drawing a new image).
So how is the best way to take my NSBitmapImageRep, and hand it off to the
main thread in such a way that I can destroy the pixels immediately while
the main thread keeps them?
Would it be best to just call [myImagerep copy], and hand that to the main
thread, and let the main thread release it once it has draw it into the
window?
_______________________________________________
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