Re: BitMap data format and autorelease
Re: BitMap data format and autorelease
- Subject: Re: BitMap data format and autorelease
- From: Jens Alfke <email@hidden>
- Date: Wed, 12 Mar 2008 09:23:05 -0700
On 12 Mar '08, at 9:09 AM, Trygve Inda wrote:
NSImage * image = [NSImage imageNamed:@"colorTest"];
NSBitmapImageRep * imageRep = [NSBitmapImageRep imageRepWithData:
[image
TIFFRepresentation]];
That will work, I think, but it's sort of inefficient, since it
requires encoding and decoding TIFF.
The quickest way would be to look at the NSImage's array of
imageRepresentations and look for an NSBitmapImageRep of the right
dimensions. Most types of images have one (the exceptions I can think
of are PDF, icns and PICT.)
If that fails, you can create a new empty NSBitmapImageRep, lockFocus
on it, draw the source image into it, and unlockFocus.
What needs to be released and retained in this case? If I release
"image",
does that also release "imageRep"?
In your code as give above, you didn't directly alloc or retain
anything, so there's nothing to release. However, none of the objects
are guaranteed to exist after the topmost autorelease pool exits. If
you want to keep a long-term reference you'll need to retain that
object. (If you want to keep using the raw pixel data, you need to
retain its owner, the image-rep.)
Finally... In my testing I always get the data as RGB with no alpha
padding
(at least in the jpg case). How can I guarantee this?
Then you definitely want to create your own NSBitmapImageRep — the
init method will give you total control over the pixel format. Then
you can lockFocus and draw whatever you want into it.
—Jens
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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