2012-07-12 50 views
0

我正在使用Cordova/jQuery Mobile构建iPhone/iPad应用程序。我使用了以下屏幕截图插件https://github.com/josemando/phonegap-plugins/commit/4c2ec54ae001ad409e4d4fe6f5ec6b9ef8b7dc3f,这款插件可以满足您的需求。它捕获屏幕截图并将其保存到我的相机胶卷相册中。然而,我怎样才能在我的Javascript中获得这个图像,最终将其上传到我的Web服务器上。cordova截图插件不能返回图像

我使用下面的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 

回答

0

我不认为这可能是工作! UIImageWriteToSavedPhotosAlbum(image,nil,nil,nil);

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;