1

I have been browsing the Internet for two days now, and apparently I'm missing something. I am trying to achieve a skewing effect for a NSImageView. I found this question on stack overflow, which suggests that it is possible. Also, in the Apple Documentation it suggests that a NSAffineTransform with a NSAffineTransformStruct is allowed.

Nevertheless: it doesn't work. The only thing I am able to perform are NSAffineTransform rotateByDegrees, NSAffineTransform scaleXBy:foo yBy:foo. Everything else doesn't show any apparent effect. I don't get any errors, just no result.

So my question is: is non-uniform scaling using NSAffineTransform not allowed for Apps on OSX? And if so, why doesn't Xcode (at least) warn me for this? Or am I missing something here (like a programming mistake)?

Any help would be appreciated!

The code I'm using:

- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];

// Drawing code here.
NSAffineTransform *rotate = [[NSAffineTransform alloc] init];
NSGraphicsContext *context = [NSGraphicsContext currentContext];

[context saveGraphicsState];
[currentImage lockFocus];
[rotate setTransformStruct:currentTransForm]; //This is filled in another routine
[rotate concat];

/* Your drawing code [NSImage drawAtPoint....]for the image goes here
 Also, if you need to lock focus when drawing, do it here.       */
CGRect imageRect = dirtyRect;

[self.image drawInRect:imageRect fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0];
[self.image unlockFocus];
[context restoreGraphicsState];
} 
Community
  • 1
  • 1
Joris
  • 11
  • 3
  • 1
    But where do you apply the transform or rotate to the image ? – Coldsteel48 Sep 25 '16 at 05:36
  • It's in a subclass of NSImageView. But I found the problem: it was due to the lockFocus. It drawed on the image itself, in stead of the screen. It's actually working now. Thank you, nevertheless! – Joris Sep 27 '16 at 19:12

0 Answers0