简体   繁体   English

如何以编程方式从画廊发送照片?

[英]How to send photo from gallery programmatically?

I need to perform "send photo" functionality. 我需要执行“发送照片”功能。 I have a web service method which takes image as parameter. 我有一个将图像作为参数的Web服务方法。 And I need to perform the following: 我需要执行以下操作:

User clicks on a button, and then photo gallery opens(also be cool to perform send photo from camera ie camera opens user make photo and then send) User select photo and click send(then my method should work). 用户单击一个按钮,然后打开图库(也可以从相机执行发送照片,也很酷,即相机打开用户制作照片然后发送)。用户选择照片并单击发送(然后我的方法应该可以使用)。

Please tell me is there any way to do it? 请告诉我有什么办法吗?

- (IBAction)upload:(id)sender {
  imagePickerViewController = [[UIImagePickerController alloc] init];
    imagePickerViewController.delegate = self;
    imagePickerViewController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:imagePickerViewController animated:YES];

}


  - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        requestType = 8;
        [picker dismissModalViewControllerAnimated:YES];
        // Access the uncropped image from info dictionary
        int seconds = [[NSDate date] timeIntervalSince1970];
        NSString *imageName = [NSString stringWithFormat:@"%d.png", seconds];
        UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        NSURL *url = [NSURL URLWithString:yourUploadLink];
        ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];


        NSData* imageData=UIImageJPEGRepresentation(image, 1.0);
        if (imageData) {
            NSLog(@"imageData exists");
        }
        [request setData:imageData withFileName:imageName andContentType:@"image/png" forKey:@"userfile"];
        [request setDelegate:self];
        [request startAsynchronous];

    //    [picker release];
    }

You need to do some research before you ask, but I'll direct you to look at the UIImagePickerController : 在询问之前,您需要做一些研究,但是我将指导您看一下UIImagePickerController

https://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html https://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html

Yes, there is. 就在这里。 You only have to build the app using: UIImagePicker for image selection (camera or library) and NSURLConnection for your communications tasks with your services. 您仅需使用以下程序来构建应用程序:UIImagePicker用于选择图像(相机或库),以及NSURLConnection用于与服务进行通信任务。

You can start here: Apple iOS Dev Library 您可以从这里开始: Apple iOS Dev Library

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM