0

我正在使用 Cordova/jQuery Mobile 构建一个 iPhone/iPad 应用程序。我使用了以下屏幕截图插件https://github.com/josemando/phonegap-plugins/commit/4c2ec54ae001ad409e4d4fe6f5ec6b9ef8b7dc3f,这是一种享受。它捕获屏幕截图并将其保存到我的相机胶卷相册中。但是,我如何才能在我的 Javascript 中获取此图像,以最终将其上传到我的 Web 服务器。

我使用以下 js 脚本执行截图功能,但它不返回图像。

Screenshot.prototype.saveScreenshot = function() {
    cordovaRef.exec("Screenshot.saveScreenshot");
};

这是 Screenshot.m 文件:

#import "Screenshot.h"

@implementation Screenshot

@synthesize webView;

- (void)saveScreenshot:(NSArray*)arguments withDict:(NSDictionary*)options
{
CGRect imageRect;
CGRect screenRect = [[UIScreen mainScreen] bounds];

// statusBarOrientation is more reliable than UIDevice.orientation
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) { 
    // landscape check
    imageRect = CGRectMake(0, 0, CGRectGetHeight(screenRect), CGRectGetWidth(screenRect));
} else {
    // portrait check
    imageRect = CGRectMake(0, 0, CGRectGetWidth(screenRect), CGRectGetHeight(screenRect));
}

UIGraphicsBeginImageContext(imageRect.size);

CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextTranslateCTM(ctx, 0, 0);
CGContextFillRect(ctx, imageRect);

[webView.layer renderInContext:ctx];

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
UIGraphicsEndImageContext();

UIAlertView *alert= [[UIAlertView alloc] initWithTitle:nil message:@"Image Saved" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}

@end
4

1 回答 1

0

我认为这行不通!

UIImageWriteToSavedPhotosAlbum(图像,无,无,无);

例如:

UIImageWriteToSavedPhotosAlbum(theImage,
   self, // send the message to 'self' when calling the callback
   @selector(thisImage:hasBeenSavedInPhotoAlbumWithError:usingContextInfo:), // the selector to tell the method to call on completion
   NULL); // you generally won't need a contextInfo here

看这里

获取图像

- (UIImage*)saveScreenshot:(NSArray*)arguments withDict:(NSDictionary*)options
....
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

....
 UIGraphicsEndImageContext();
....

return image;
于 2012-07-12T21:03:24.983 回答