gpt4 book ai didi

iphone - UIImagePickerControllerSourceTypePhotoLibrary编辑时如何添加图片叠加?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:20:57 24 4
gpt4 key购买 nike

我尝试到处寻找这个问题的答案,但找不到任何有用的信息。

基本上,我希望用户从相册中挑选一张图片,然后让应用程序以编辑/裁剪模式显示图片。

在这个编辑屏幕上,我想显示一个覆盖屏幕,供用户用来对齐他的图像。

然后他单击保存按钮,通过合并图像来保存编辑后的图片和叠加图像。

我唯一找不到的方法是在编辑屏幕中添加覆盖图像!

在以下情况下我可以很容易地做到这一点:

imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;

但是当:

imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

我不能使用:

imagePicker.cameraOverlayView = overlayGraphicView;

那是我的问题。

此外,如果我添加一个 UIimage 作为 subview 而不是这个叠加层,即使用户从相册中选择他的图像,它也会保留在屏幕上。我只希望在选择要编辑的图像之后以及在编辑完成后将其保存到相册之前显示叠加层。

感谢您的帮助。

方法如下:

- (IBAction)pickPhotoButton:(id)sender {
NSLog(@"Pick a Current Photo Button Pressed...");

// Create image picker controller
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

// Set source to the camera
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

// Delegate is self
imagePicker.delegate = self;

// Allow editing of image ?
imagePicker.allowsEditing = YES;

// Show image picker
[self presentModalViewController:imagePicker animated:YES];
}

这是我保存到相册的方法:

// Save the image to photo album
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:@"UIImagePickerControllerEditedImage"];

// Combine image with overlay before saving!!
image = [self addOverlayToImage:image];

// Save image
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

[picker release];
}

最佳答案

您可以成为UIImagePickerController 对象的委托(delegate)并敏锐地观察UINavigationControllerDelegate 方法- navigationController:didShowViewController:animated:navigationController:willShowViewController:animated:。您可以知道第二个 View Controller 何时出现,然后将您的叠加层添加到 View Controller 的 View 中。示例用法如下所示 –

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
if ( [navigationController.viewControllers count] == 2 ) {
overlayView.center = CGPointMake(135, 135);
overlayView.bounds = CGRectZero;

[viewController.view addSubview:overlayView];

[UIView beginAnimations:@"animateTableView" context:nil];
[UIView setAnimationDuration:0.4];
[overlayView setFrame:CGRectMake( 50, 50, 220, 220)];
[UIView commitAnimations];
}
}

关于iphone - UIImagePickerControllerSourceTypePhotoLibrary编辑时如何添加图片叠加?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6113563/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com