message composer sample code/photo picker sample code

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

  1. macrumors member

    Joined:
    Mar 13, 2011
    #1
    Hey

    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

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    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.

    Code:
    - (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();
        UIGraphicsEndImageContext();
       
        imageData = UIImageJPEGRepresentation(newImage, 0.5);
        imageDataTotal = [imageData copy];
    }
    Code:
        NSData *imageData;
        NSData *imageDataTotal;
    Don't forget to do to the copy, and work with that. Because of a BAD_EXCES.
    =)
     
  3. thread starter macrumors member

    Joined:
    Mar 13, 2011
    #3
    Hey thanks for your post, but where would i define the imagefromcamera at?
     
  4. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #4
    Code:
     
    INTERFACE
       UIImagePickerController* imagePickerController;
        UIImage *imageFromCamera;
        NSData *imageData;
        NSData *imageDataTotal;
    }
    
    @property (nonatomic, retain) UIImage *imageFromCamera;
    
    - (void) startTheCamera;
    
     

Share This Page