我需要执行“发送照片”功能。我有一个Web服务方法,它将图像作为参数。我需要执行以下操作:
用户点击按钮,然后照片库打开(也很酷,可以从相机发送照片,即相机打开用户制作照片,然后发送) 用户选择照片并单击发送(然后我的方法应该工作)。
请告诉我有什么办法吗?
答案 0 :(得分:4)
- (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];
}
答案 1 :(得分:2)
您需要先做一些研究,但我会指导您查看UIImagePickerController
:
答案 2 :(得分:0)
是的,有。您只需使用以下内容构建应用程序:UIImagePicker用于图像选择(相机或库),NSURLConnection用于与您的服务进行通信任务。
您可以从这里开始:Apple iOS Dev Library