• 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 Images....
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Rotating Images....


  • Subject: Rotating Images....
  • From: Jerry LeVan <email@hidden>
  • Date: Sat, 26 Jun 2004 20:06:11 -0400

For the past couple of days I have been beating my head against
the wall, getting square eyed reading posts on Mammasan, trying
to figure out how to:

Given an image A, make and image B where the image B is a rotated
by a multiple of ninty degrees version of A.

About all I can do is produce "kaleidoscopes"...

Been using stuff that looks like this with square images...

Forgive the crummy looking code but this is about the
200th version. ( Image A fits tightly in its frame....)

seems like this should be faq.... Could anyone point
me to something that might enlighten me...

Jerry

- (void)createScaledImage: anImage
{

NSGraphicsContext *currentContext; // The current graphics context
NSAffineTransform *imageRotation; // Rotation about center of bounds
NSPoint center; // Center of receiver's bounds
NSSize imageSize; // Size of the image to draw

NSSize scaledRect;
NSImage *tmpImage=NULL;
float scaleFactor=[theSlider floatValue];
tmpImage = [anImage copy];
[tmpImage setScalesWhenResized:YES];
//do the scaling arithmetic
NSSize tmpRect = [tmpImage size];
scaledRect.width= tmpRect.width*scaleFactor;
scaledRect.height=tmpRect.height*scaleFactor;
[tmpImage setSize:scaledRect];
imageRotation = [NSAffineTransform transform];
currentContext = [NSGraphicsContext currentContext];
center = NSMakePoint(scaledRect.width/2, scaledRect.height/2);
imageSize = [tmpImage size];
NSLog(@"Before Lock");
// return;
[tmpImage lockFocus];
[currentContext saveGraphicsState];

// Create a transformation to rotate the coordinate system degrees about the center of the bounds
[imageRotation translateXBy:center.x yBy:center.y];
[imageRotation rotateByDegrees:-90.0];
[imageRotation translateXBy:(-center.x )yBy:(-center.y)];

// Transform the current coordinate system
[imageRotation concat];
NSLog(@"Before DrawAtPoint");
// Draw the image in the current coordinate system
[ tmpImage drawAtPoint:NSMakePoint(0,0) fromRect:NSMakeRect(0,0, imageSize.width, imageSize.height) operation:NSCompositeCopy fraction:1.0];
// [ tmpImage drawInRect:NSMakeRect(0,0,imageSize.width,imageSize.height) fromRect:NSMakeRect(0,0, imageSize.width, imageSize.height) operation:NSCompositeCopy fraction:1.0];
NSLog(@"After Draw...");
// Restore the previous graphics state
[currentContext restoreGraphicsState];
[tmpImage unlockFocus];

//NSLog(@"ScaledImage release cnt(2):%d",[tmpImage retainCount]);
// Set the image into the view
[theImageView setImage:tmpImage];
[bigView setImage:tmpImage];
//NSLog(@"ScaledImage release cnt(3):%d",[tmpImage retainCount]);

[theImageView setFrameSize:[tmpImage size]];
//[theImageView setNeedsDisplay];
[tmpImage release];
//NSLog(@"ScaledImage release cnt(leaving):%d",[tmpImage retainCount]);
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Rotating Images....
      • From: Allan Odgaard <email@hidden>
  • Prev by Date: Re: URL formatting in NSAttributedString
  • Next by Date: Re: displaying a sheet with new document
  • Previous by thread: *WORKAROUND* Re: Buttons work under 10.3.4 but not 10.2.8
  • Next by thread: Re: Rotating Images....
  • Index(es):
    • Date
    • Thread