• 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
Re: Rotating an image
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rotating an image


  • Subject: Re: Rotating an image
  • From: Ian was here <email@hidden>
  • Date: Thu, 4 Oct 2007 22:29:15 -0700 (PDT)

Here's a link to an old project of mine. It's a 2D
sprite engine that uses Quartz. I abandoned it in
favor of OpenGL, mainly due to how slow it is. It has
code for rotating images. Hope this helps.

http://www.howleware.com/games/osx/sprite_engine_quartz.zip



--- Development <email@hidden> wrote:

> Ok, I can rotate the view of an image easily by
> setting the rotation
> of the NSImageView. but I need to be able to
> actually rotate the
> image in the view and then adjust the size of the
> view and redisplay.
> I thought that this would be done by NSBezierPath
> and
> NSAffineTransform. I still think this is the case
> but my code only
> produces either completely blank images OR
> completely black images or
> an image with a black rectangle offset to the right
> by some number of
> pixels or another. I've spent the past two hours on
> the developer
> site and in google but the answer has not been
> apparent to me. Below
> is the flawed code. I have subclassed NSImage view
> and added this
> code to the subclass:
>
> -(NSImage*)rotateImage:(float)degrees
> {
> 	NSRect sourceImageRect = [[self cell]
> rectCoveredByImageInBounds:
> [self bounds]];
> 	NSAffineTransform * xform = [NSAffineTransform
> transform];
> 	NSBezierPath * xformedPath = [NSBezierPath
> bezierPathWithRect:sourceImageRect];
> 	[xform rotateByDegrees:degrees];
> 	xformedPath = [xform transformBezierPath:[self
> imagePath]];
> 	NSRect newRect =[xformedPath bounds];
> 	NSImage * newImage = [[NSImage
> alloc]initWithSize:newRect.size];
> 	[newImage lockFocus];
> 		[[NSColor blackColor] set];
> 		[xformedPath fill];
> 		[[self image] drawInRect:newRect
> fromRect:sourceImageRect
> operation:NSCompositeSourceIn fraction:1.0];
> 	[newImage unlockFocus];
> 	return newImage;
> }
>
> - (NSBezierPath *) imagePath {
> 	NSRect sourceImageRect = [[self cell]
> rectCoveredByImageInBounds:
> [self bounds]];
> 	return [NSBezierPath
> bezierPathWithRect:sourceImageRect];
> 	}
> _______________________________________________
>
> 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
>




____________________________________________________________________________________
Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out.
http://answers.yahoo.com/dir/?link=list&sid=396545433
_______________________________________________

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

References: 
 >Rotating an image (From: Development <email@hidden>)

  • Prev by Date: Rotating an image
  • Next by Date: Re: multiple methods named 'xxx' found.
  • Previous by thread: Rotating an image
  • Next by thread: Re: Rotating an image
  • Index(es):
    • Date
    • Thread