I just don't get NSAffineTransform and compositeToPoint:
I just don't get NSAffineTransform and compositeToPoint:
- Subject: I just don't get NSAffineTransform and compositeToPoint:
- From: James Housley <email@hidden>
- Date: Sun, 13 Mar 2005 20:53:44 -0500
I really appreciate all the help and pointers I have been getting on
this list, both in answers to my questions and from reading the
archives.
GOAL: To select a region of an image, crop to a new image (ie just
copy that portion). I have started with some good samples from Apple.
With their code I have it selecting and copying the image, the problem
is that it creates an image the same size of the original image.
I have tried changing sourceImageRect on line #10 to newImageBounds.
And that created an image of the right size, but only contained my
selection if I select from the lower left corner.
I tried playing with pathAdjustment on line #16 and that didn't help
I tried using compositeToPoint:fromRect:operation on line #23, but that
didn't help.
1: // Returns an autoreleased NSImage, consisting of the selected
portion of the reciever's image.
2: // If there's no selection, this method will return the original
image.
3: - (NSImage *)croppedImage
4: {
5: NSRect sourceImageRect = [[self cell]
rectCoveredByImageInBounds:[self bounds]];
6: NSRect newImageBounds = NSIntersectionRect([selectionMarker
selectedRect], sourceImageRect);
7:
8: if (!NSIsEmptyRect(newImageBounds))
9: {
10: NSImage *newImage = [[NSImage alloc]
initWithSize:sourceImageRect.size];
11:
12: NSAffineTransform *pathAdjustment = [NSAffineTransform transform];
13:
14: NSBezierPath *croppingPath = [selectionMarker selectedPath];
15:
16: [pathAdjustment translateXBy: -NSMinX(sourceImageRect) yBy:
-NSMinY(sourceImageRect)];
17: croppingPath = [pathAdjustment
transformBezierPath:[selectionMarker selectedPath]];
18:
19: [newImage lockFocus];
20: [[NSGraphicsContext currentContext] setShouldAntialias:NO];
21: [[NSColor blackColor] set];
22: [croppingPath fill];
23: [[self image] compositeToPoint:NSZeroPoint
operation:NSCompositeSourceIn];
24: [newImage unlockFocus];
25:
26: return [newImage autorelease];
27: }
28: return [self image];
29: }
I have read the docs on NSAffineTransform and what I can find on the
net. But what it comes down to is I just don't understand it.
1) Is there a good place that explains these? I have spent over two
days and I just don't get it.
2) How do I fix the above code.
Thanks,
Jim
--
/"\ ASCII Ribbon Campaign .
\ / - NO HTML/RTF in e-mail .
X - NO Word docs in e-mail .
/ \ -----------------------------------------------------------------
email@hidden http://www.FreeBSD.org The Power to Serve
email@hidden http://www.TheHousleys.net
---------------------------------------------------------------------
Do not meddle in the affairs of dragons, for you are crunchy and taste
good with ketchup.
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden