cordova s​​creenshot plugin无法返回图片

时间:2012-07-12 19:21:40

标签: ios plugins jquery-mobile screenshot cordova

我正在使用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

1 个答案:

答案 0 :(得分:0)

我认为这不起作用!

UIImageWriteToSavedPhotosAlbum(image,nil,nil,nil);

例如:

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

look here

获取图片

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

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

return image;