程序收到 uiimagepickercontroller 的信号 0
我有一个应用程序,用户可以从相机拍照,图像显示在图像视图中。 第一次工作正常,但第二次应用程序崩溃,留下内存警告级别=1
我用谷歌搜索并尝试了所有可能的方法,但没有用
下面是我在应用程序中使用的代码
UIImagePickerController *imgpicker;
@property(nonatomic,retain) UIImagePickerController *imgpicker;
@synthesize imgpicker;
if(actionSheet.tag==1)
{
NSLog(@"button index:%i",buttonIndex);
if(buttonIndex == 0)
{ NSLog(@"button index for camera:%i",buttonIndex);
if(self.imgpicker==nil){
self.imgpicker=[[UIImagePickerController alloc]init];
self.imgpicker.delegate =self;
self.imgpicker.sourceType=UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:self.imgpicker animated:YES];
[imgpicker release];
return;
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSLog(@"didFinishPickingMediaWithInfo editing info:%@",info);
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
imageview = [[UIImageView alloc] initWithFrame:CGRectMake(65, 10, 75, 75)];
NSData *newjpg = UIImageJPEGRepresentation(image, 0.5);
[imageview setImage:[UIImage imageWithData:newjpg]];
[scrollView addSubview:imageview];
[self.view addSubview:scrollView];
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
请帮助我
I have an app where user can take picture from camera and image is displayed in imageview.
It works fine for the first time but the second time app is crashed leaving memory warning level=1
I google around and tried all possible ways but no use
Below is the code i used in my app
UIImagePickerController *imgpicker;
@property(nonatomic,retain) UIImagePickerController *imgpicker;
@synthesize imgpicker;
if(actionSheet.tag==1)
{
NSLog(@"button index:%i",buttonIndex);
if(buttonIndex == 0)
{ NSLog(@"button index for camera:%i",buttonIndex);
if(self.imgpicker==nil){
self.imgpicker=[[UIImagePickerController alloc]init];
self.imgpicker.delegate =self;
self.imgpicker.sourceType=UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:self.imgpicker animated:YES];
[imgpicker release];
return;
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSLog(@"didFinishPickingMediaWithInfo editing info:%@",info);
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
imageview = [[UIImageView alloc] initWithFrame:CGRectMake(65, 10, 75, 75)];
NSData *newjpg = UIImageJPEGRepresentation(image, 0.5);
[imageview setImage:[UIImage imageWithData:newjpg]];
[scrollView addSubview:imageview];
[self.view addSubview:scrollView];
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
Please help me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试将其更改
为
:并删除此行:
如果多次显示图像选择器,则每次选择器完成时分配的图像视图都会泄漏内存。
您每次还将图像视图添加到滚动视图,并将滚动视图添加到视图控制器的视图。您只需执行一次,然后更新图像视图上的
image
属性。试试这个:
Try changing this:
to this:
and remove this line:
If you're showing the image picker more than once, you're leaking memory from the image view that gets allocated every time the picker finishes.
You're also adding the image view to the scroll view and the scroll view to the view controller's view every time. You just need to do it once, and the update the
image
property on the image view.Try this:
请在 AppDelegate 类中创建 UIImagePickerController 对象,并在 AppDidFinishloading 方法中进行初始化:didFinishLaunchingWithOptions。在 appDelegate dealloc 方法上实现它。
您可以从 appdelegate 类在所需的视图控制器页面中访问它。
请不要在需要时创建任何时候的 UIImagePickerController 对象并实现它。
这可能对你有帮助。
Please create UIImagePickerController object in your AppDelegate class and initialize in your AppDidFinishloading method : didFinishLaunchingWithOptions. Realese it on appDelegate dealloc method.
You can access it in your needed view controller Page from appdelegate class.
Please do not create evertytime UIImagePickerController object when u needed and realese it.
This might help you.
请使用此代码:
App Delegate
// .h
// .m
//RootView 控制器
// .h
// .m
这肯定会对你有帮助。
Please use this code :
App Delegate
// .h
// .m
//RootView Controller
// .h
// .m
This will definitely help u.