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 PROTECTED]


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to