gpt4 book ai didi

ios - 以编程方式将图像保存到相机胶卷

转载 作者:行者123 更新时间:2023-12-01 18:21:02 24 4
gpt4 key购买 nike

关于这个问题,我在这里经历了很多线程,但没有取得太大成功。

我正在浏览网站上的图像,点击并按住显示我的操作表、保存照片或取消。它确实保存,但它保存的是白色图像,而不是图像本身。我尝试的另一种方法仅保存为屏幕截图(不是我所追求的)。

我不是在追求特定的图像,只是任何格式的图像。

这是我正在使用的所有当前代码。

    UILongPressGestureRecognizer *gestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
webView.userInteractionEnabled = YES;
gestureRecognizer.minimumPressDuration = 0.3;
gestureRecognizer.delegate = self;
gestureRecognizer.numberOfTouchesRequired = 1;
[webView addGestureRecognizer:gestureRecognizer];

}

- (void)handleLongPress:(UILongPressGestureRecognizer*)gestureRecognizer{
if (gestureRecognizer.state == UIGestureRecognizerStateBegan){
//get the image view that the user selected and save it as your selectedImageView property
UIImageView *pressedImageView = (UIImageView *)gestureRecognizer.view;
self.selectedImageView = pressedImageView;

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Save Photo", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
[actionSheet showInView:self.view];
[actionSheet release];

}}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
case 0:

[self savePhoto];

break;

default:
break;

}}

-(void)savePhoto{

UIGraphicsBeginImageContext(_selectedImageView.bounds.size);
[_selectedImageView drawRect:_selectedImageView.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

UIImageWriteToSavedPhotosAlbum(image,
self,
@selector(savedPhotoImage:didFinishSavingWithError:contextInfo:),
NULL);


}

- (void) savedPhotoImage:(UIImage *)image
didFinishSavingWithError:(NSError *)error
contextInfo:(void *)contextInfo
{
NSString *message = @"This image has been saved to your Photos album";
if (error) {
message = [error localizedDescription];
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
message:message
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}

savePhoto 是我认为搞砸的。

提前谢谢你。

更新:
所以这说它可以保存它,但没有任何显示。
-(void)savePhoto {

NSLog(@"TAPPED");
//Touch gestures below top bar should not make the page turn.
//EDITED Check for only Tap here instead.
CGPoint touchPoint = [touch locationInView:self.view];

NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
bool pageFlag = [userDefaults boolForKey:@"pageDirectionRTLFlag"];
NSLog(@"pageFlag tapbtnRight %d", pageFlag);

NSString *imgURL = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).src", touchPoint.x, touchPoint.y];
NSString *urlToSave = [webView stringByEvaluatingJavaScriptFromString:imgURL];
NSLog(@"urlToSave :%@",urlToSave);
NSURL * imageURL = [NSURL URLWithString:urlToSave];
NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage * image = [UIImage imageWithData:imageData];
imageView.image = image;//imgView is the reference of UIImageView

UIImageWriteToSavedPhotosAlbum(image,
self,
@selector(savedPhotoImage:didFinishSavingWithError:contextInfo:),
NULL);
}

最佳答案

决定回到这一点,因为我正在处理我的应用程序中的其他事情。决定采取不同的方法。而不是乱七八糟地试图发现触摸或其他东西。我只是调用了保存操作将图像下载到相机胶卷。现在很简单,我可以看到它是如何工作的。如果有人好奇,我就是这样做的。

总而言之,在我的 webview 中,我创建了一个将打开图像扩展的 Controller 。在我看来,使它更容易本地化。从那里,我在导航栏中添加了一个保存按钮。从这就是我所做的。

-(void)savePhoto {
NSURL *imageURL = receivedURL;
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];
UIImageWriteToSavedPhotosAlbum(image, self, @selector(savedPhotoImage:didFinishSavingWithError:contextInfo:), nil);
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}

- (void) savedPhotoImage:(UIImage *)image
didFinishSavingWithError:(NSError *)error
contextInfo:(void *)contextInfo
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
message:@"This image has been saved to your camera roll"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[alert show];
[alert release];
}

希望这可以帮助某人:)

关于ios - 以编程方式将图像保存到相机胶卷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17354970/

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