• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Rotating an NSImage around it's own center as well as offset to origin
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Rotating an NSImage around it's own center as well as offset to origin


  • Subject: Rotating an NSImage around it's own center as well as offset to origin
  • From: Alexander Hartner <email@hidden>
  • Date: Sun, 21 Feb 2010 23:43:19 +0000

I would like to rotate and offset an NSImage and then draw it onto an NSImageView. So far I figured out to use Quartz and use CGContextRotateCTM and CGContextTranslateCTM. I got the offset working just fine using this, but as soon as I introduce the rotation it rotates the image relative to the origin, rather then the centre. I figure I need to do a combination of CGContextTranslateCTM to move the centre of the image to the origin, then apply a CGContextRotateCTM to rotate it and then move it back, but I can't figure out how to best do this.

Are there any other options of doing this please let me know. I had a look online, but all the suggestions I found seem too complicated as there must be a simple solution to this (I hope).

...
int resultWidth = 1600;
int resultHeight = 1200;

float foregroundXoffset= 50;
float foregroundYoffset= 50;
float foregroundRotation = 10;

NSData *tiff_data = [[NSData alloc] initWithData:[[backgroundImage image] TIFFRepresentation]];
NSBitmapImageRep * bitmap = [[NSBitmapImageRep alloc] initWithData:tiff_data];

CGImageRef imageBackground = CGImageRetain([bitmap CGImage]);
int width = 0;
int height = 0;
width = CGImageGetWidth(imageBackground);
height = CGImageGetHeight(imageBackground);

CGContextSaveGState(context);

CGContextRotateCTM(context, foregrounRotation);
CGContextTranslateCTM (context, foregroundXoffset, foregroundYoffset);
CGContextDrawImage(context, imageRect, imageBackground);
CGImageRelease(imageBackground);

CGContextRestoreGState(context);
...

Thanks in advance
Alex_______________________________________________

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

  • Follow-Ups:
    • Re: Rotating an NSImage around it's own center as well as offset to origin
      • From: Ron Fleckner <email@hidden>
  • Prev by Date: Re: Extract keys, values from 'usrf' Record Type NSAppleEventDescriptor?
  • Next by Date: Re: Rotating an NSImage around it's own center as well as offset to origin
  • Previous by thread: Re: Extract keys, values from 'usrf' Record Type NSAppleEventDescriptor?
  • Next by thread: Re: Rotating an NSImage around it's own center as well as offset to origin
  • Index(es):
    • Date
    • Thread