Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 05-20-2009, 12:37 PM   #3 (permalink)
nujohn
Registered Member
 
Join Date: Oct 2008
Posts: 9
nujohn is on a distinguished road
Send a message via Yahoo to nujohn
Default Thanks for the snippet...I made one minor adjustment

It was giving me problems (image ended up in the wrong location)when I move the image around i.e. translation. My image size was different from the view size and in my case that's the screen size (320X480) I noticed that if my image were exactly the same size as the view size then the existing code works perfectly otherwise there's the problem I described. Also I wasn't sure why it was doing a draw twice so I cut that out. Here are the results of my changes:

-(UIImage*) getCroppedImageFromViewUIView *)view imageUIImage *)image {
// Begin the drawing
CGRect rect = view.bounds;
UIGraphicsBeginImageContext(CGSizeMake(rect.size.w idth,rect.size.height));
CGContextRef ctx = UIGraphicsGetCurrentContext();
// Clear whole thing
CGContextClearRect(ctx, rect);

// Transform the image (as the image view has been transformed)
CGContextTranslateCTM(ctx, rect.size.width*0.5, rect.size.height*0.5);
CGContextConcatCTM(ctx, view.transform);
CGContextTranslateCTM(ctx, -rect.size.width*0.5, -rect.size.height*0.5);

// Tanslate and scale upside-down to compensate for Quartz's inverted coordinate system
CGContextTranslateCTM(ctx, 0.0, rect.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);

// Draw view into context
CGContextDrawImage(ctx, rect, image.CGImage);

// Create the new UIImage from the context
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

// End the drawing
UIGraphicsEndImageContext();
return newImage;
}


Again thanks for sharing.
nujohn is offline   Reply With Quote
 

» Advertisements
» Online Users: 469
18 members and 451 guests
7twenty7, buggen, ClerurcifeDer, Clouds, Duncan C, e2applets, iAppDeveloper, ipodphone, KarlJay, linkmx, orninn, ryantcb, sacha1996, Sami Gh, stanny, Steven.C, Studder, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,638
Threads: 94,102
Posts: 402,824
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Studder
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:44 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.