即使从 Appdelegate 声明后,UIImagePickerController 仍存在问题

发布于 2024-11-27 01:44:34 字数 2474 浏览 0 评论 0原文


我们正在做一个使用 UIImagePickerController 的照片应用程序。为了仅维护控制器的一个实例,我们在 appdelegate 中声明了它。但即使在这样做之后,内存泄漏仍然存在。有谁可以帮助我们吗
这是我们的代码

在 AppDelegate.h

UIImagePickerController *imagePicker;
@property (nonatomic, retain) UIImagePickerController *imagePicker;

在 AppDelegate.m

@synthesize imagePicker;

和 applicationDidFinishLaunching 事件中

imagePicker = [[[UIImagePickerController alloc] init] autorelease];

需要在 CameraView 中调用此 UIImagePicker 在 CameraView.h

RedDawnMediaAppDelegate *appDel;
@property (nonatomic, retain) RedDawnMediaAppDelegate *appDel;

CameraView.m

@synthesize appDel;

appDel=(RedDawnMediaAppDelegate*)[[UIApplication sharedApplication] delegate];

appDel.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
// Hide the camera controls:
appDel.imagePicker.showsCameraControls = NO;
appDel.imagePicker.navigationBarHidden = YES;
appDel.imagePicker.delegate = self;

// Make the view full screen:
appDel.imagePicker.wantsFullScreenLayout = YES;
appDel.imagePicker.cameraViewTransform =       CGAffineTransformScale(appDel.imagePicker.cameraViewTransform, CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y);

// Now incert our overlay view (it has to be here cuz it's a modal view):
appDel.imagePicker.cameraOverlayView = overlayView;

[self presentModalViewController:appDel.imagePicker animated:YES];

在 didFinishPickingMediaWithInfo 中

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

[appDelegate.imagePicker dismissModalViewControllerAnimated:YES];

uploadImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; 
[uploadImage retain];
NSData *imageData = UIImageJPEGRepresentation(uploadImage, 0.5);
//[uploadImage release];
UIImage *image=[UIImage imageWithData:imageData];


self.view.frame = CGRectMake(0, 0, 320, 480);
self.wantsFullScreenLayout = YES;
objCameraImageView = [[CameraImageView alloc] initWithNibName:@"CameraImageView" bundle:[NSBundle mainBundle]];
[objCameraImageView setParentController:self];
objCameraImageView.cameraImage = image;
[image release];
uploadImage = nil;
[self.view addSubview:objCameraImageView.view];
[self release];
}

的 viewDidLoad拍摄照片后,我们将在另一个视图中显示预览。所以我们多次调用Cameraview,这导致内存泄漏,请帮助。


we are doing a photo application in which UIImagePickerController is used. For maintaining only one instance of the controller we have declared it in the appdelegate. But even after doing that memory leak is still there. Can any one please help us
Here's our code

In AppDelegate.h

UIImagePickerController *imagePicker;
@property (nonatomic, retain) UIImagePickerController *imagePicker;

In AppDelegate.m

@synthesize imagePicker;

and in applicationDidFinishLaunching event

imagePicker = [[[UIImagePickerController alloc] init] autorelease];

Need to call this UIImagePicker in CameraView

In CameraView.h

RedDawnMediaAppDelegate *appDel;
@property (nonatomic, retain) RedDawnMediaAppDelegate *appDel;

In CameraView.m

@synthesize appDel;

and in viewDidLoad

appDel=(RedDawnMediaAppDelegate*)[[UIApplication sharedApplication] delegate];

appDel.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
// Hide the camera controls:
appDel.imagePicker.showsCameraControls = NO;
appDel.imagePicker.navigationBarHidden = YES;
appDel.imagePicker.delegate = self;

// Make the view full screen:
appDel.imagePicker.wantsFullScreenLayout = YES;
appDel.imagePicker.cameraViewTransform =       CGAffineTransformScale(appDel.imagePicker.cameraViewTransform, CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y);

// Now incert our overlay view (it has to be here cuz it's a modal view):
appDel.imagePicker.cameraOverlayView = overlayView;

[self presentModalViewController:appDel.imagePicker animated:YES];

in didFinishPickingMediaWithInfo

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

[appDelegate.imagePicker dismissModalViewControllerAnimated:YES];

uploadImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; 
[uploadImage retain];
NSData *imageData = UIImageJPEGRepresentation(uploadImage, 0.5);
//[uploadImage release];
UIImage *image=[UIImage imageWithData:imageData];


self.view.frame = CGRectMake(0, 0, 320, 480);
self.wantsFullScreenLayout = YES;
objCameraImageView = [[CameraImageView alloc] initWithNibName:@"CameraImageView" bundle:[NSBundle mainBundle]];
[objCameraImageView setParentController:self];
objCameraImageView.cameraImage = image;
[image release];
uploadImage = nil;
[self.view addSubview:objCameraImageView.view];
[self release];
}

After taking a photo we are showing the preview in another view. so we are invoking the Cameraview for several times which is leading to Memory leak pls help.

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

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

发布评论

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

评论(1

红墙和绿瓦 2024-12-04 01:44:35

首先,您无需担心仅维护一个 imagepickercontroller 实例。从相机获取图像比您正在做的事情简单得多。

请参阅我的帖子:

如何从相机和相机拍照通过编程方式保存在照片库中?

因为我在获取图像完成后释放了选择器。不会有内存泄漏!

First of all you dont need to worry about maintaining only one instance of imagepickercontroller. Getting an image from camera is much simpler than what you are doing.

See my post here:

How to take picture from Camera & saved in Photo Gallery by programmatically?

since Im releasing the picker when its done getting the image. There wont be memory leak!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文