Re: Fastest way to resize an image?
Re: Fastest way to resize an image?
- Subject: Re: Fastest way to resize an image?
- From: Heinrich Giesen <email@hidden>
- Date: Sat, 22 Nov 2008 20:47:43 +0100
Hi,
On 22.11.2008, at 19:36, Jean-Nicolas Jolivet wrote:
Problem is... the ImageRep technique works well when I'm just
scaling an image..it's quite fast too, however I am also cropping
(in some cases)... and unfortunately, without the "fromRect"
parameter, it's pretty much impossible to crop...
for a more comfortable drawing method you need an extra NSImage, but
the overhead is very small.
Replace
[self drawInRect:NSMakeRect( 0, 0, [sourceRep pixelsWide],
[sourceRep pixelsHigh])];
(as you already noticed there is a typo: "self" is wrong, it should
have been "sourceRep", sorry )
with: (written in mail)
NSImage *tmpImg = [[NSImage alloc] initWithSize:NSZeroSize];
[tmpImg addRepresentation: sourceRep];
[tmpImg drawInRect:NSMakeRect( 0, 0, [sourceRep pixelsWide],
[sourceRep pixelsHigh])
fromRect:cropRect // or NSZeroRect when using the whole image
operation:NSCompositeSourceOver
fraction:1.0];
If the newRep shall have the same resolution as the source, we can do
it with:
float dpiX = 72.0*[sourceRep pixelsWide]/[sourceRep
size].width; // source x resolution
NSSize size = [newRep size];
size.width = 72.0*[newRep pixelsWide] / dpiX;
[newRep setSize:size];
(similar setting the y resolution)
Heinrich
--
Heinrich Giesen
email@hidden
_______________________________________________
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