Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Rotating Images....



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.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.