iphone相机上传

时间:2012-07-31 05:44:18

标签: objective-c ios cocoa-touch camera uiimagepickercontroller

xcode中的

4.3我试图在应用程序中使用相机拍摄照片并使用该图像或图片库中的图像添加到此处------->

(void) ShareButton {
[AddThisSDK showAddThisButtonInView:self.view
                          withFrame:CGRectMake(75, 50, 150, 50)
                             forImage:[UIImage imageNamed:@"**HERE**"]
                          withTitle:@"Share Your Dinner"
                        description:@""];
}

我的相机完全正常工作我只是不知道如何获取图像名称,如果您需要更多信息或更好的解释随时可以询问

2 个答案:

答案 0 :(得分:0)

而不是:

 forImage:[UIImage imageNamed:@"**HERE**"]

你应该使用这个:

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *myImageFromCamera = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    [AddThisSDK showAddThisButtonInView:self.view
                          withFrame:CGRectMake(75, 50, 150, 50)
                             forImage:myImageFromCamera
                          withTitle:@"Share Your Dinner"
                        description:@""];
}

UIImagePickerController的didFinishPickingMediaWithInfo委托方法可用于检测用户何时按下了选择器中的“使用”按钮。如上所示,它会为用户拍摄的图像创建UIImage,然后我们将此图像设置为AddThisSDK共享图像。

请注意,这是一种过度简化,并不会直接执行您想要的操作。为了正确完成此操作,您需要全局声明UIImage,以便可以在didFinishPickingMediaWithInfo中设置图像,然后在AddThisSDK共享方法中调用它。

注意: forImage:[UIImage imageNamed:@"**HERE**"]告诉方法应该使用保存在应用程序包中的名为“ HERE ”的图像。

答案 1 :(得分:0)

-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *myImageFromCamera = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    [AddThisSDK showAddThisButtonInView:self.view
                              withFrame:CGRectMake(75, 50, 150, 50)
                               forImage:myImageFromCamera
                              withTitle:@"Share Your Dinner"
                            description:@""];

    NSString *mediaType = [info
                           objectForKey:UIImagePickerControllerMediaType];
    [self dismissModalViewControllerAnimated:YES];
    if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
        UIImage *image = [info
                          objectForKey:UIImagePickerControllerOriginalImage];

        imageView.image = image;
        if (newMedia)
            UIImageWriteToSavedPhotosAlbum(image,
                                           self,
                                           @selector(image:finishedSavingWithError:contextInfo:),
                                           nil);
}

这完美无缺,您拍摄或从照片中选择的照片会显示分享按钮