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 11-19-2009, 06:18 AM   #23 (permalink)
kobkobn
Registered Member
 
Join Date: Nov 2009
Posts: 1
kobkobn is on a distinguished road
Default

Quote:
Originally Posted by ralmeida View Post
IT WORKS

All above code with minimal tweaks:

Code:
...
#include <math.h>

static inline double radians (double degrees) {return degrees * M_PI/180;}
...


-(UIImage *)resizeImage:(UIImage *)image :(NSInteger) width :(NSInteger) height {
	
	CGImageRef imageRef = [image CGImage];
	CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef);
	CGColorSpaceRef colorSpaceInfo = CGColorSpaceCreateDeviceRGB();
	
	if (alphaInfo == kCGImageAlphaNone)
		alphaInfo = kCGImageAlphaNoneSkipLast;
	
	CGContextRef bitmap;
	
	if (image.imageOrientation == UIImageOrientationUp || image.imageOrientation == UIImageOrientationDown) {
		bitmap = CGBitmapContextCreate(NULL, width, height, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, alphaInfo);
		
	} else {
		bitmap = CGBitmapContextCreate(NULL, height, width, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, alphaInfo);
		
	}
	
	if (image.imageOrientation == UIImageOrientationLeft) {
		NSLog(@"image orientation left");
		CGContextRotateCTM (bitmap, radians(90));
		CGContextTranslateCTM (bitmap, 0, -height);
		
	} else if (image.imageOrientation == UIImageOrientationRight) {
		NSLog(@"image orientation right");
		CGContextRotateCTM (bitmap, radians(-90));
		CGContextTranslateCTM (bitmap, -width, 0);
		
	} else if (image.imageOrientation == UIImageOrientationUp) {
		NSLog(@"image orientation up");	
		
	} else if (image.imageOrientation == UIImageOrientationDown) {
		NSLog(@"image orientation down");	
		CGContextTranslateCTM (bitmap, width,height);
		CGContextRotateCTM (bitmap, radians(-180.));
		
	}
	
	CGContextDrawImage(bitmap, CGRectMake(0, 0, width, height), imageRef);
	CGImageRef ref = CGBitmapContextCreateImage(bitmap);
	UIImage *result = [UIImage imageWithCGImage:ref];
	
	CGColorSpaceRelease(colorSpaceInfo);
	CGContextRelease(bitmap);
	CGImageRelease(ref);
	
	return result;	
}


Hi,
thanks a lot for the info.
i've used the code and it does what it's expected but i do encounter some memory problems after using it.

in my app, the user will select a photo form the photo lib, after selecting it, the application will display the photo in a UIImageView and later will be taken form the imageView for some processing.
I'm a bit new to iphoen programming and most chances i'm doing something wrong.
Since i want to fix the rotation problem, i use the method inorder ot resize the photo to the original size (by that i just fix the rotatin problem).
I call the routine with the selected image size from the DidFinishPickingMediaWithInfo method (is it ok to call it from there ?)
and after one or two selections i start to get memory warnings.
what i do in DidFinishPickingMediaWithInfo is basicly :

(assuming img is the original selected image

[myImageView setImage:[self resizeImage:img height:img.size.height width:img.size.width];

after that, as i said ... memory problem.

Am i missing a way to only change the size for displaying the photo but using it later in its original size ?

thanks a lot,
Kobi.

Last edited by kobkobn; 11-19-2009 at 06:22 AM.
kobkobn is offline   Reply With Quote
 

» Advertisements
» Online Users: 562
13 members and 549 guests
akacaj, alphy, baramuse, bignoggins, Domele, Gudus, ilmman, jaunsmith71, MartinB, ngaikwad, Paul Slocum, rky, Son of a Beach
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,323
Threads: 93,989
Posts: 402,413
Top Poster: BrianSlick (7,978)
Welcome to our newest member, jaunsmith71
Powered by vBadvanced CMPS v3.1.0

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