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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 11-21-2008, 11:55 AM   #21 (permalink)
Stitch
Registered Member
 
Stitch's Avatar
 
Join Date: Aug 2008
Posts: 401
Default

I'm trying to resize UIImages before saving them as images to the documents folder.

I've implemented the code below from PhoneyDeveloper which is working well for resizing my images.

The trouble is the images are rotated 90 degrees anti-clockwise. Is there an easy way to fix this? Or another solution to resize UIImages? It must be documented though.

Thanks

Quote:
Originally Posted by PhoneyDeveloper View Post
Code:
//	==============================================================
//	resizedImage
//	==============================================================
// Return a scaled down copy of the image.  

UIImage* resizedImage(UIImage *inImage, CGRect thumbRect)
{
	CGImageRef			imageRef = [inImage CGImage];
	CGImageAlphaInfo	alphaInfo = CGImageGetAlphaInfo(imageRef);
	
	// There's a wierdness with kCGImageAlphaNone and CGBitmapContextCreate
	// see Supported Pixel Formats in the Quartz 2D Programming Guide
	// Creating a Bitmap Graphics Context section
	// only RGB 8 bit images with alpha of kCGImageAlphaNoneSkipFirst, kCGImageAlphaNoneSkipLast, kCGImageAlphaPremultipliedFirst,
	// and kCGImageAlphaPremultipliedLast, with a few other oddball image kinds are supported
	// The images on input here are likely to be png or jpeg files
	if (alphaInfo == kCGImageAlphaNone)
		alphaInfo = kCGImageAlphaNoneSkipLast;

	// Build a bitmap context that's the size of the thumbRect
	CGContextRef bitmap = CGBitmapContextCreate(
				NULL,
				thumbRect.size.width,		// width
				thumbRect.size.height,		// height
				CGImageGetBitsPerComponent(imageRef),	// really needs to always be 8
				4 * thumbRect.size.width,	// rowbytes
				CGImageGetColorSpace(imageRef),
				alphaInfo
		);

	// Draw into the context, this scales the image
	CGContextDrawImage(bitmap, thumbRect, imageRef);

	// Get an image from the context and a UIImage
	CGImageRef	ref = CGBitmapContextCreateImage(bitmap);
	UIImage*	result = [UIImage imageWithCGImage:ref];

	CGContextRelease(bitmap);	// ok if NULL
	CGImageRelease(ref);

	return result;
}
__________________
BUZZER! : iTunes Library Music Quiz (1 or 2 Player)
Stitch is offline   Reply With Quote
 

» Advertisements
» Online Users: 294
15 members and 279 guests
ADY, BdR, BrianSlick, dacapo, Joseph Nardone, laurielaptop, M@realobjects, mizzytheboy, oztemel, poisenden, Sunny46, syver, TheWebWizz, VikMyr, XRumerTest
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,876
Threads: 89,225
Posts: 380,701
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jorge599
Powered by vBadvanced CMPS v3.1.0

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