gitawego / cordova-screenshot

screenshot plugin for cordova/phonegap
Other
211 stars 168 forks source link

how to save images in Albums in iphone #36

Open Gowrilink opened 9 years ago

Gowrilink commented 9 years ago

Hi gitawego,

in android images save in pictures folde,But in iPhone screenshot images not appear in camera role (albums) how to save images in Camera albums in iPhone.Now i am using iPhone 5 ,cordova 3.5

karladler commented 9 years ago

+1 for this. What's the best way on iPad / iPhone to export the pictures e.g. to Dropbox?

Merkane commented 9 years ago

Not sure if the awsner is still needed but I needed the screenshot to save in the Photos application on iOS. I managed to save my screenshot in the Photos application and appear in Camera Roll and My Photo Stream. I changed the code in the saveScreenshot() function in the Screenshot.m class. The image variable contains the screenshot which is just taken by your device. Instead of using the UIImageJPEGRepresentation() function and then write it to your device I used the UIImageWriteToSavedPhotosAlbum() function. This works like a charm for me!

sqwk commented 7 years ago

What is the best way to use this? When changing the code as described in the comment above, my app will no longer compile. (Fails with "Check dependencies")

palmthree-studio commented 4 years ago

Not sure if the awsner is still needed but I needed the screenshot to save in the Photos application on iOS. I managed to save my screenshot in the Photos application and appear in Camera Roll and My Photo Stream. I changed the code in the saveScreenshot() function in the Screenshot.m class. The image variable contains the screenshot which is just taken by your device. Instead of using the UIImageJPEGRepresentation() function and then write it to your device I used the UIImageWriteToSavedPhotosAlbum() function. This works like a charm for me!

  • (void)saveScreenshot:(CDVInvokedUrlCommand)command { NSString filename = [command.arguments objectAtIndex:2]; NSNumber quality = [command.arguments objectAtIndex:1]; NSString path = [NSString stringWithFormat:@"%@.jpg",filename]; NSString jpgPath = [NSTemporaryDirectory() stringByAppendingPathComponent:path]; UIImage image = [self getScreenshot]; UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); //NSData imageData = UIImageJPEGRepresentation(image); //[imageData writeToFile:jpgPath atomically:NO]; CDVPluginResult pluginResult = nil; NSDictionary *jsonObj = [ [NSDictionary alloc] initWithObjectsAndKeys : jpgPath, @"filePath", @"true", @"success", nil ]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:jsonObj]; [self writeJavascript:[pluginResult toSuccessCallbackString:command.callbackId]]; }

My hero ! Five years later and it's work like a charm !

I've not succeed to add all of this code in my screenshot.m, but I just copied this line in bottom of line 37 "UIImage *image" :

UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

Simple, no ? 😄

Hope it will help someone in the future 😉

PS : If Xcode thrown an error, you just have to restart it and it will be good !