1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

message composer sample code/photo picker sample code

Discussion in 'iPhone/iPad Programming' started by ljg93, May 31, 2011.

  1. macrumors member


    I was using the photo picker sample code along with the message composer sample code

    I threw in a button on the photo picker sample code toolbar to go to a email, how would i go about attaching the image that is on screen of the photo picker into the email?
  2. macrumors 65816


    Well, you could save the image representation u get from the camera, into a local variable. and add that into the email or something.

    Here is some code including to scale it, so it doesn't clog up memory when u are trying to use it as background or similair.

    - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
        // Access the uncropped image from info dictionary
        UIImage* image = (UIImage* ) [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        imageFromCamera = [image copy];
        // Save image
        UIImageWriteToSavedPhotosAlbum(imageFromCamera, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
        [picker release];
        CGSize size = CGSizeMake(768, 1024);
        UIGraphicsBeginImageContext(size);// a CGSize that has the size you want
        [imageFromCamera drawInRect:CGRectMake(0,0,size.width,size.height)];
        //image is the original UIImage
        UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
        imageData = UIImageJPEGRepresentation(newImage, 0.5);
        imageDataTotal = [imageData copy];
        NSData *imageData;
        NSData *imageDataTotal;
    Don't forget to do to the copy, and work with that. Because of a BAD_EXCES.
  3. macrumors member

    Hey thanks for your post, but where would i define the imagefromcamera at?
  4. macrumors 65816


       UIImagePickerController* imagePickerController;
        UIImage *imageFromCamera;
        NSData *imageData;
        NSData *imageDataTotal;
    @property (nonatomic, retain) UIImage *imageFromCamera;
    - (void) startTheCamera;

Share This Page