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:08:49 -0700
- Thread-topic: NSImage from bitmap - then delete bitmap
>
>> On 22 Jul 2016, at 3:37 PM, Trygve Inda <email@hidden> wrote:
>>
>> I create an NSBitmapImageRep:
>>
>> [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
>> pixelsWide:pixelSize.width
>> pixelsHigh:pixelSize.height
>> bitsPerSample:8
>> samplesPerPixel:4
>> hasAlpha:YES
>> isPlanar:NO
>> colorSpaceName:NSDeviceRGBColorSpace
>> bitmapFormat:NSAlphaFirstBitmapFormat
>> bytesPerRow:pixelSize.width * 4
>> bitsPerPixel:32]
>>
>> I then get the address by sending a "bitmapData" message to the object
>>
>> After filling it with image data, I call:
>>
>> NSImage* image =
>> [[NSImage alloc] initWithData:[myImageRep TIFFRepresentation]];
>>
>> So now I have an NSImage. What happens if I delete/release myImageRep (my
>> NSBitmapImageRep)?
>
> Nothing. The rep isn’t doing anything after this point; you can release it
> safely.
>
>> Has the call to NSImage copied my pixels so that they are self-contained
>> within the NSImage?
>
> Yes.
>
> But that’s not a great way to do this. You’ve made an image, you’ve encoded it
> as TIFF data, then you’ve made a new image, which has decoded the TIFF data to
> make a new image rep/bitmap.
>
> You could just add the representation directly to a new NSImage (warning:
> typed into Mail, check method names):
>
> NSImage* myImage = [[NSImage alloc] initWithSize:NSMakeSize(width,height)];
>
> [myImage addRepresentation:theBitmapIMadeFirst];
>
> [theBitmapIMadeFirst release]; // because NSImage retained it
I don't think the second part will work because of my workflow:
At Launch: Create pixel buffer that is 1000 x 1000 pixels
Looping thread
1. Fill pixel buffer with pixels based on some algorithm
2. create an NSImage with these pixels
3. pass it to the main thread to be drawn in a window
Restart the loop with a slightly modified algorithm
If calling this:
[myImage addRepresentation:theBitmapIMadeFirst];
Only causes the NSImage to retain it, then when I change the pixels in the
bitmap, they get changed in the NSImage.
I need the NSImage to keep the pixels as they existed when I created it.
_______________________________________________
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