[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Extracting from NSImage (NSImageView)
From: |
Vaisburd, Haim |
Subject: |
RE: Extracting from NSImage (NSImageView) |
Date: |
Thu, 3 Jun 2004 16:43:49 -0700 |
Andreas Hoeschler <ahoesch@smartsoft.de> wrote:
> Hi Vaisburd,
My name is Tima :-)
> [compositeImage compositeToPoint: fromRect: operation: fraction]
> [compositeImage drawAtPoint: fromRect: operation: fraction:]
>
> Both methods still aren't implemented (latest snapshot).
> Is anybody actually working on this?
Yes, I'm curious about this too. Maybe the people in the know can answer?
> Is there any other approach to accomplish - compositing images
> and extracting a subregion - on GNUstep?
Yes. Here is an adapted piece of code from PhotoClip
(http://www.vaisburd.net/PhotoClip/index.html), development has been
interrupted, but I still hope to continue ;)
Cropping works if one draws NSImageRep instead of NSImage.
@implementation NSImage (PhotoClip)
- (NSImage *) imageFromRect: (NSRect) rect
{
NSImage * canvas = [[NSImage alloc] initWithSize: rect.size];
// we are going to draw self on canvas and return canvas
[canvas lockFocus];
// Prepare affine transformation to translate 'self'
// so that rect.origin maps to (0,0)
NSAffineTransform * xform = [NSAffineTransform transform];
[xform translateXBy: -rect.origin.x yBy: -rect.origin.y];
// Apply transform
[xform concat];
// Get NSImageRep of image
NSImageRep * rep = [self bestRepresentationForDevice: nil];
[rep drawAtPoint: NSZeroPoint];
[canvas unlockFocus];
return [canvas autorelease];
}
@end
Enjoy!
Tima.