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

Reply
 
LinkBack Thread Tools Display Modes
Old 09-23-2009, 06:06 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2009
Location: Orlando, FL
Posts: 3
Default Saving a UIImage / Orientation issues

Hi everyone,

I'm trying to write an app that uses images retrieved from the UIImagePickerController. These images may be fairly large. I would like to manipulate them and then be able to save them back to the photo album with UIImageWriteToSavedPhotosAlbum. My problem is that when I run the following code on a photo taken in portrait mode, the resulting saved image comes out sideways and distorted. If the source image is landscape, the resulting saved image is perfect. What am I missing here?

Code:
    // let's assume workImage is a UIImageView that has an image loaded in it
    int w = workImage.image.size.width;
    int h = workImage.image.size.height;
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    
    CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
    
    // draw the Master image on the context
    CGContextDrawImage(context, CGRectMake(0, 0, w, h), workImage.image.CGImage);

    // do other manipulation/drawing to the context here
    // ...
    // ...

    // Create the image to save
    CGImageRef imageRef = CGBitmapContextCreateImage(context);
    UIImage *saveImage = [[UIImage alloc] initWithCGImage:imageRef];
    
    // close up the context
    CGContextRelease(context);
    CGColorSpaceRelease(colorSpace);
        
    // save the image
    UIImageWriteToSavedPhotosAlbum(saveImage, nil, nil, nil); 
    
    // release the saveImage
    [saveImage release];
One more thing, I checked out the imageOrientation of the returned image and it's always UIImageOrientationUp in both cases.

Last edited by dogsplayingpoker; 09-23-2009 at 09:28 PM. Reason: Additional information
dogsplayingpoker is offline   Reply With Quote
Reply

Bookmarks

Tags
cgcontextdrawimage, cgcontextref, cgimageref, uiimage

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: 245
24 members and 221 guests
ADY, AragornSG, bookesp, chillyh, dacapo, Dani77, Davey555, Dominus, dre, glenn_sayers, HemiMG, JasonR, karlam963, M.A.S., marshusensei, mer10, nobre84, Oral B, prchn4christ, Raggou, Rudy, spiderguy84, themathminister, viniciusdamone
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,765
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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