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 > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-06-2011, 02:39 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 245
samurle is on a distinguished road
Question Resize and Crop UIImage?

UIImageView has a content viewing mode called UIViewContentModeScaleAspectFill, however,
I would like to have this view written to a real, static image.

So, essentially, my image needs to be resized and cropped. I've found some code here:
Resize a UIImage the right way — Trevor’s Bike Shed

But it doesn't seem to work.

This is what I'm trying to do:

Code:
// This is the original 640x480 image (aspect ratio 1.3333)
UIImage *orgImage = [UIImage imagedName:imagePath];

// New 320x480 image (aspect ratio 0.6666)
CGSize newSize = CGSizeMake( 320, 480 );
CGRect newRect = CGRectMake( 0,0, newSize.width, newSize.height );

UIImage *retImage = [orgImage resizedImageWithContentMode:UIViewContentModeScaleAspectFill
                              bounds:newSize
                              interpolationQuality:kCGInterpolationHigh];

UIImageView *tmp = [[UIImageView alloc] initWithImage:retImage];
tmp.frame = newRect;
[self.view insertSubview:tmp atIndex:0];
[tmp release];

But, this method, resizedImageWithContentMode, doesn't work as expected. My image is not cropped,
and its aspect ratio is not preserved. Instead, it works like AspectFit, which is wrong.

How can I resize and crop my image, while preserving its aspect ratio?
Does anyone use this code?
samurle is offline   Reply With Quote
Reply

Bookmarks

Tags
crop, resize, uiimage, uiimageview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 402
18 members and 384 guests
13dario13, 7twenty7, eski, EvilElf, glenn_sayers, HemiMG, iOS.Lover, jarv, LunarMoon, n00b, pbart, Pudding, QuantumDoja, sacha1996, Sami Gh, UMAD, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,122
Posts: 402,906
Top Poster: BrianSlick (7,990)
Welcome to our newest member, yuncarl28
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:21 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0