> On 22 Jul 2016, at 3:37 PM, Trygve Inda <[email protected]> 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

…

done.



All NSImage is is a “box” in which a bunch of NSImageReps reside. It sometimes 
makes those reps itself from data, etc, but you can make them yourself and add 
them. It’s way more efficient.

—Graham



_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to