2

使用默认相机拍摄后如何直接从 iPhone 上传照片?

目前我使用以下逻辑(Appaccelerator)存储照片:

  <script language="JavaScript">
    var medium = {};
Rf.media.push(medium);

medium.title = 'Photo';
medium.extension = 'jpg';

medium.create = function () {

var medium = this;

Ti.Media.showCamera({
    // TODO: disallow video for ios
    saveToPhotoGallery: false,
    showControls: true,
    success: function (media_item) {
        var name = Rf.util.timestamp()+'.'+medium.extension;
        write_to_new_file(name, media_item.media, function (file) {
        });
    },
});
};
medium.view = function (file) {
var photoView = Ti.UI.createImageView({
    image: file,
});

var photoWindow = Ti.UI.createWindow({
    backgroundColor: Rf.style.backgroundColor,
    color: Rf.style.foregroundColor,
    layout: 'vertical',
    modal: true,
});
photoWindow.add(photoView);
photoWindow.open();
};
4

1 回答 1

-1
-(void)camera  
{  

    NSLog(@"image upload");
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Image from..." delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Camera", @"Image Gallary", nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleAutomatic;
    actionSheet.alpha=0.90;
    actionSheet.tag = 1;

    //[actionSheet showFromTabBar:appDelegate.tabbarcontroller.tabBar];

    [actionSheet showInView:appdelegate.window];

    [actionSheet release];

}

-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex  
{ 

    if (buttonIndex==actionSheet.cancelButtonIndex) 
    {   cam = YES;
        NSLog(@"cancel");

        [actionSheet dismissWithClickedButtonIndex:actionSheet.cancelButtonIndex animated:YES];

    }
    else if(buttonIndex==0)
    {
        cam = NO;  
        NSLog(@"Camera");

        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self; 
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        picker.wantsFullScreenLayout = YES;


        picker.allowsEditing=YES; 
        actionsheet = YES;
        [self presentModalViewController:picker animated:YES]; 


    }
    else if(buttonIndex==1)

    {
        cam = NO;
        NSLog(@"Gallery");

        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self; 
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        picker.wantsFullScreenLayout = YES;


        picker.allowsEditing=YES;
                actionsheet = YES;
        [self presentModalViewController:picker animated:YES];



    }


}


-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo  
{


    [picker dismissModalViewControllerAnimated:YES];

    [self.captureimage setImage:image];

}

 convert it to image data then we can upload it  
  self.imagedata = UIImagePNGRepresentation(self.captureimage.image);
于 2012-06-13T11:27:01.553 回答