Take Screenshot of ArcGIS Map View Programmatically for iOS - ios

I am trying to take a screenshot of an ArcGIS map view programmatically. I haven't seen any code in the ArcGIS library to make this easy. I'm really trying to create a UIImage of the map view including any feature layers that are currently being displayed. I tried using UIGraphicsBeginImageContext for the arcgisMapView and on the superview containing the arcgisMapView, but both attempts return a blank view for the arcgisMapView area.
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *mapImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(mapImage, nil, nil, nil);
and
UIGraphicsBeginImageContext(arcgisMapView.bounds.size);
[arcgisMapView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *mapImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(mapImage, nil, nil, nil);
Please help and thanks.

Use exportImageWithCompletion:.
https://developers.arcgis.com/ios/latest/swift/sample-code/take-screenshot.htm
And sample source.
https://github.com/Esri/arcgis-runtime-samples-ios/tree/master/arcgis-ios-sdk-samples/Maps/Take%20screenshot
Guess ArcGIS uses another custom layer, not just self.view.layer.

Related

How to capture high quality snapshot image of Sprite Kit SKView?

I followed the traditional way of drawing the view into UIImage :
UIGraphicsBeginImageContextWithOptions(controller.skView.bounds.size, NO, 1.0);
[controller.skView drawViewHierarchyInRect:controller.skView.bounds afterScreenUpdates:YES];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
I have tried to set the third parameter in UIGraphicsBeginImageContextWithOptions to 2.0 or larger,however the quality of the Image doesn't get better.
Here I post two images(1st is captured by the code,2nd is captured by pressing Home + power button ,this function is supported by system).
I want to know if there is a way to make it better.Appreciating any help!

How do I programmatically combine multiple UIImages into one long UIImage?

I'm using the code from here How can I programmatically put together some UIImages to have one big UIImage? to combine multiple screenshots into one large vertical image. However, I'm having trouble calling this function to combine multiple images together using:
imageContainer = [UIImage imageByCombiningImage:imageContainer withImage:viewImage];
How do I call this UIImage+combine category to merge the library of images together?
Here's my Code:
- (void) printScreen {
// this is a method that starts the screenshot taking process
// this line is necessary to capture the completion of the scrollView animation
_webView.scrollView.delegate = self;
// save the first image
UIGraphicsBeginImageContextWithOptions(_webView.bounds.size, NO, 0);
[_webView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
// scroll to the next section
[_webView.scrollView scrollRectToVisible:CGRectMake(0, _webView.frame.size.height, _webView.frame.size.width, _webView.frame.size.height) animated:YES];
}
- (void )scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
// at this point the _webView scrolled to the next section
// I save the offset to make the code a little easier to read
CGFloat offset = _webView.scrollView.contentOffset.y;
UIGraphicsBeginImageContextWithOptions(_webView.bounds.size, NO, 0);
// note that the below line will not work if you replace _webView.layer with _webView.scrollView.layer
[_webView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(image1, nil, nil, nil);
// if we are not done yet, scroll to next section
if (offset < _webView.scrollView.contentSize.height) {
[_webView.scrollView scrollRectToVisible:CGRectMake(0, _webView.frame.size.height+offset, _webView.frame.size.width, _webView.frame.size.height) animated:YES];
}
UIImage *image = [UIImage imageByCombiningImage:image1 withImage:image2];
[[self theNewImageView] setImage:image];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
NSLog(#"%# printScreen Image", image);
NSLog(#"%# printScreen Image2", image2);
}
Edit:
At this point I've tried alot of different things. Im new to objective C development so I've been digging deep into the Apple developer docs and other good places for info like stack and lynda.
Im seeing two different codes from the logs: printScreen Image2, printScreen Image, but i just cant get the function to call the new category.
I'm able to write all the images in separate pieces to the photo album and I can merge image1 or image2 into one image but not the both images or all images.
I figured it out! Right in front of my face the entire time. I needed to add the call to the category within the scrollViewDidEndScrollingAnimation then save to the UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);. I probably tried a couple different version of this solution but I renamed some variables early on to align with my project which screwed everything up.

Keep transparency in screenshot iOS

I am taking screenshot of a particular View in my Xib file with the following code...
UIView* captureView = self.view;
UIGraphicsBeginImageContextWithOptions(captureView.bounds.size, NO , 0.0f);
[captureView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
It works fine and saves JPG image to camera roll.
But problem is, There is another UIImageView on the top of my View, that UIImageView has a semi-transparent image in it.
My screenshot doesn't preserve that transparency in the screenshot it is taking.
I want to keep the transparency as it is in the actual screen.
How can you preserve the transparency in the screenshot?
If you specify "No" for the opaque property, your image must include an alpha channel for this to work. Check that your image has an alpha channel.
JPGs don't have transparency so as soon as you convert it to JPG alpha is gone.
This is a known limitation of UIImageWriteToSavedPhotosAlbum
it doesn't keep png.
try this. this code working for me
UIGraphicsBeginImageContext(baseViewOne.frame.size);
[[baseViewOne layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage * screenshota = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
also check cocoa coder screen shots
NSData* imdata = UIImagePNGRepresentation(_snapshotImgView.image);
UIImage* snapshotPNG = [UIImage imageWithData:imdata];
UIImageWriteToSavedPhotosAlbum(snapshotPNG, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);

How do I "combine" two UIImageViews into one image? Like Photoshop Layer merging?

I have a drawing app where you have one UIImageView that serves as the "drawing layer." You have another UIImageView beneath it that is the "image layer," containing the image you are drawing on. I like having this separation. However, I want the user to be able to "save and email" the drawing they have made on top of the image as one unified image. How do I do this?
Your UIImageView instances must be part of a UIView hierachy so all you need to do is paint that top containing UIView into a context
UIGraphicsBeginImageContext(CGSizeMake(width, height));
[container.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *fimage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
or if that gives you trouble successively paint the two images into a context
UIGraphicsBeginImageContext(CGSizeMake(width, height));
[image1.layer renderInContext:UIGraphicsGetCurrentContext()];
[image2.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *fimage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
from there you can write the data where you choose
NSData *data = UIImagePNGRepresentation(fimage);
Pass that data into the MailComposer setup.

xcode screenshot with advertisement

I use this to save a screenshot of the app when pushing a button:
UIGraphicsBeginImageContext(_containerView.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
It used to take things correctly (i.e. everything on the screen) but now puts a white bar where the advertisement is (iAd/AdMob) and it just looks ugly. It looks much better with the ad in the screenshot. Any ideas what might be going on?

Resources