Open tbh726 opened 9 years ago
sooo can someone please implement this!?!?!?!
it exists already if you check the ios code.
navigator.screenshot.URI(function(error,res){
if(error){
console.error(error);
}else{
html = '<img style="width:50%;" src="'+res.URI+'">';
document.body.innerHTML = html;
}
},50);
omg you just saved my project!
I'm using this plugin to do native like transitions using Famous Engine to achieve 60fps transitions. I'll post the proof of concept when I'm done.
Thank you!!!
Actually I can't seem to get this working now.
All it does is return the same image no matter what view I change on the page :/
android 5.1
I'm trying to edit your code here, not too much Java experience. I'm not using crosswalk btw.
I see we are cacheing the bitmap:
View view = webView.getView().getRootView();
view.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
I'm pretty sure this is where my problem of the same image returning every time.
OK so I fixed it by changing
View view = webView.getView().getRootView();
to
View view = webView.getView()
:D
Hi, great plugin... i saw that iOS did not have URI, this was what i needed for bot android and iOS... not saying this is perfect (not an objective c type but can play), but it works great for me for URI.
in Screenshot.h
in Screenshot.m
(void)getScreenshotAsURI:(CDVInvokedUrlCommand*)command {
CGRect imageRect; CGRect screenRect = [[UIScreen mainScreen] bounds];
// statusBarOrientation is more reliable than UIDevice.orientation UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)) { if (orientation != UIInterfaceOrientationLandscapeLeft && orientation != UIInterfaceOrientationLandscapeRight) { // landscape check imageRect = CGRectMake(0, 0, CGRectGetWidth(screenRect), CGRectGetHeight(screenRect)); } else { // portrait check imageRect = CGRectMake(0, 0, CGRectGetWidth(screenRect), CGRectGetHeight(screenRect)); }
} else { 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)); } }
// Adds support for Retina Display. Code reverts back to original if iOs 4 not detected. if (NULL != UIGraphicsBeginImageContextWithOptions) UIGraphicsBeginImageContextWithOptions(imageRect.size, NO, 0); else UIGraphicsBeginImageContext(imageRect.size);
CGContextRef ctx = UIGraphicsGetCurrentContext(); [[UIColor blackColor] set]; CGContextTranslateCTM(ctx, 0, 0); CGContextFillRect(ctx, imageRect);
if ([webView respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) { [webView drawViewHierarchyInRect:webView.bounds afterScreenUpdates:YES]; } else { [webView.layer renderInContext:ctx]; }
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
NSString* imageData = [UIImagePNGRepresentation(image) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
UIGraphicsEndImageContext();
CDVPluginResult* pluginResult = nil;
NSDictionary *jsonObj = [ [NSDictionary alloc] initWithObjectsAndKeys : imageData, @"URI", @"true", @"success", nil ];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:jsonObj];
[self writeJavascript:[pluginResult toSuccessCallbackString:command.callbackId]];
}