使用 IBAction 时无法从 UIImagePickerController 显示 UIImage

发布于 2024-09-02 18:41:28 字数 1108 浏览 3 评论 0原文

我是 xcode 新手。我尝试从 UIImagePickerController 中选择图像并 然后按一个按钮显示该图像。但是模拟器崩溃了。 在.h中我使用

UIImage *dispimage; //in order to make a global image
-(IBAction) open;
-(IBAction) print;

.m中我有

- (void)viewDidLoad {
    self.imgPicker = [[UIImagePickerController alloc] init];
    self.imgPicker.allowsImageEditing = YES;
    self.imgPicker.delegate = self;
    self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
dispimage = [info objectForKey:UIImagePickerControllerOriginalImage];   
[self dismissModalViewControllerAnimated:YES];
}

-(IBAction) open{
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    [self presentModalViewController:imagePicker animated:YES];
    [imagePicker release];
};
-(IBAction) print{
imageView.image=dispimage;
};

当按下“打印”按钮时,sdk崩溃。 :( 如有任何帮助,将不胜感激

提前致谢

I 'm new to xcode. I try to select an image from the UIImagePickerController and
then display this image pressing a button. But the simulator crashes.
In the .h I use

UIImage *dispimage; //in order to make a global image
-(IBAction) open;
-(IBAction) print;

In the .m I have

- (void)viewDidLoad {
    self.imgPicker = [[UIImagePickerController alloc] init];
    self.imgPicker.allowsImageEditing = YES;
    self.imgPicker.delegate = self;
    self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
dispimage = [info objectForKey:UIImagePickerControllerOriginalImage];   
[self dismissModalViewControllerAnimated:YES];
}

-(IBAction) open{
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    [self presentModalViewController:imagePicker animated:YES];
    [imagePicker release];
};
-(IBAction) print{
imageView.image=dispimage;
};

When the button "print" is pressed, the sdk crashes. :(
Any help would be appreciated

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一腔孤↑勇 2024-09-09 18:41:28

这是从 UIImagePickerController 获取图像的代码

-(void)viewDidLoad 
{
     self.imgPicker = [[UIImagePickerController alloc] init]; 
     self.imgPicker.allowsImageEditing = YES;
     self.imgPicker.delegate = self; 
     self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{
     dispimage = [[info objectForKey:UIImagePickerControllerOriginalImage]retain];
     [picker dismissModalViewControllerAnimated:YES]; 
}

-(IBAction)open
{
    if(self.imgPicker == nil)
    { 
         self.imgPicker = [[UIImagePickerController alloc] init]; 
         self.imgPicker.allowsImageEditing = YES;
         self.imgPicker.delegate = self; 
         self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
    [self presentModalViewController:self.imagePicker animated:YES]; 
    [self.imagePicker release]; 
}

-(IBAction) print
{ 
      if(dispimage != nil)
      {
            imageView.image=dispimage; 
      }
};

Here is the code to get images from UIImagePickerController

-(void)viewDidLoad 
{
     self.imgPicker = [[UIImagePickerController alloc] init]; 
     self.imgPicker.allowsImageEditing = YES;
     self.imgPicker.delegate = self; 
     self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{
     dispimage = [[info objectForKey:UIImagePickerControllerOriginalImage]retain];
     [picker dismissModalViewControllerAnimated:YES]; 
}

-(IBAction)open
{
    if(self.imgPicker == nil)
    { 
         self.imgPicker = [[UIImagePickerController alloc] init]; 
         self.imgPicker.allowsImageEditing = YES;
         self.imgPicker.delegate = self; 
         self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
    [self presentModalViewController:self.imagePicker animated:YES]; 
    [self.imagePicker release]; 
}

-(IBAction) print
{ 
      if(dispimage != nil)
      {
            imageView.image=dispimage; 
      }
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文