Re: BitMap data format and autorelease
Re: BitMap data format and autorelease
- Subject: Re: BitMap data format and autorelease
- From: Trygve Inda <email@hidden>
- Date: Wed, 12 Mar 2008 17:03:41 +0000
- Thread-topic: BitMap data format and autorelease
>
> 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.
So I create an NSBitmapImageRep with:
- (id)initWithBitmapDataPlanes:(unsigned char **)planes
pixelsWide:(NSInteger)width pixelsHigh:(NSInteger)height
bitsPerSample:(NSInteger)bps samplesPerPixel:(NSInteger)spp
hasAlpha:(BOOL)alpha isPlanar:(BOOL)isPlanar colorSpaceName:(NSString
*)colorSpaceName bitmapFormat:(NSBitmapFormat)bitmapFormat
bytesPerRow:(NSInteger)rowBytes bitsPerPixel:(NSInteger)pixelBits
There is a method similar to this without bitmapFormat... How is that
interpreted then?
How than can I draw a jpg into this space?
I will then later need to take this bitmap and create a new jpg with it.
Thanks,
Trygve
_______________________________________________
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