Re: Saving PNG files from NSImage
Re: Saving PNG files from NSImage
- Subject: Re: Saving PNG files from NSImage
- From: Martin Linklater <email@hidden>
- Date: Mon, 29 Aug 2011 16:28:51 +0100
Thanks for the info guys.
The method below is working great.
On 29 Aug 2011, at 14:38, Marco Tabini wrote:
> Hi Martin—
>
> On 2011-08-29, at 9:11 AM, Martin Linklater wrote:
>
>> Thanks Marco. When I call representationUsingType I get this:
>>
>
> You need to first convert the representation to an NSBitmapImageRep, which can then be converted to PNG; for example:
>
> - (NSData *) PNGRepresentationOfImage:(NSImage *) image {
> // Create a bitmap representation from the current image
>
> [image lockFocus];
> NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0, 0, image.size.width, image.size.height)];
> [image unlockFocus];
>
> return [bitmapRep representationUsingType:NSPNGFileType properties:Nil];
> }
>
> I wrote a simple app (requires Xcode 4.1 with ARC enabled) for you to try out. You can grab it from here.
>
> Cheers,
>
>
> —Mt.
_______________________________________________
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