I'm working on an app in which I am looking to take a screenshot of the map to record where a person was when the action was performed, which is then sent in a report back to the server. I do not want the person to see the map pop up while the screenshot is being taken and the user should be oblivious of the screenshot until they review the report.
I have looked at the following question:
how to take a screen shot from a mapview
But they are making the map visible in order to take the screenshot.
Thank you for your time.
If understand correctly, you have a view somewhere and you do not want it on screen, but you want to capture an image of it.
UIGraphicsBeginImageContextWithOptions(mapView.bounds.size,mapView.alpha, mapView.contentScaleFactor);
CGContextRef context = UIGraphicsGetCurrentContext();
mapView.backgroundColor = [UIColor whiteColor];
[mapView.layer renderInContext:context];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Related
Hi am a noob at PDF generation and currently am displaying a 3d bar charts in my application in glview which is in side a uiview. Now i want to generate a PDF document from the uiview which contains a text view and a glview. Am able to generate a PDF from text but where as GL View am unable to proceed.even i tried for a possibility over the net but unable to get any info regarding this.Can someone help me by providing the solution whether this can be possible or not.Thanks in Advance
You can ask any UIView to give you an image (which might be a start) via something like:
- (UIImage *) imageRepresentation {
// render myself (or more correctly, my layer) to an image
UIGraphicsBeginImageContext(self.bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetShouldSmoothFonts(context, false);
CGContextSetShouldAntialias(context, false);
[self drawLayer:self.layer inContext:context];
[self.layer renderInContext:context];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
After that, you might be able to get a PDF representation of it, or investigate calls like CGPDFDocumentCreateWithURL to construct one yourself from the image.
You can use CoreGraphic's PDF-APIs to creating and drawing to a PDF.
See Apple's guide for more details.
I am perfoming image sequences animation is on main thread.
At the same time i want to take snapshot of device screen in back ground.
And by using that snapshots i want make video..
Thanks,
Keyur Prajapati
For taking the screenshots while running the image animations
use
[self.view.layer.presentationLayer renderInContext:UIGraphicsGetCurrentContext()];
instead of
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
it will take screenshots while runing animations
iOS uses Core Animation as the rendering system. Each UIView is backed by a CALayer. Each visible layer tree is backed by a presentation tree. The layer tree contains the object model values for each layer, i.e., values you set when you assign a value to a layer property (A and B). The presentation tree contains the values that are currently being presented to the user as an animation takes place (interpolated values between A and B).
If you're doing it in CoreAnimation you can render the layer contents into a bitmap using -renderInContext:. Have a look at Matt Longs Tutorial. It's for Objective-C on the Mac, but it can be easily converted for use on the iPhone.
Create one another thread where you can do this:
//Create rect portion for image if full screen then 320X480
CGRect contextRect = CGRectMake(0, 0, 320, 480);
// this is whate you need
UIGraphicsBeginImageContext(contextRect.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
viewImage is the image which you needed.
You can write this code in function which can be called timely bases like per 5 seconds or according to your requirements.
Hope this is what you needed.
I have managed to add an iAd to a table cell which is working as expected. When the user taps a table cell I want to perform a specific animation, so I captured the view using the code below into a UIImage then transform the image. This works perfectly apart form the fact that the captured image contains everything appart from the iAd. I have swapped iAds for AdMob and it works fine, so must be something to do with the way an iAd is attached to the view tree. Any one have any ideas on how to capture the iAd image.
CGRect rect = view.bounds;
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer.superlayer renderInContext:context];
UIImage *imageCaptureRect;
imageCaptureRect = UIGraphicsGetImageFromCurrentImageContext();
self.capturedImage = imageCaptureRect;
UIGraphicsEndImageContext();
I would hazard a guess that this is by design. Apple uses the personal information they have on their users and their account histories to target iAds to the correct demographics. If Apple allowed developers to determine which iAds a user was receiving, they would be leaking this personal information. Consider the possibility that an iAd was targeted to people under the age of 30. An application that captured your iAds could watch out for this advert and determine your age bracket.
i have a UIView having 3 UITableView and need to take screen shot. But problem is invisible part of the 3 tables . Can anyone help to find a way to take screen shot of the whole view including complete scrolled contents of the tables.
This helps get the contents of a layer (ie. and thus a UIView)
UIGraphicsBeginImageContext(tableView.frame.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[tableView.layer renderInContext:ctx];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
I'd like to get the image that is being displayed on the UIImagePickerController when user uses the camera. And when I get I want to process the image and display instead of regular camera view.
But the problem is when I want to get the camera view, the image is just a black rectangle.
Here's my code:
UIView *cameraView = [[[[[[imagePicker.view subviews] objectAtIndex:0]
subviews] objectAtIndex: 0]
subviews] objectAtIndex: 0];
UIGraphicsBeginImageContext( CGSizeMake(320, 427) );
[cameraView.layer renderInContext: UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
imageToDisplay.image = [PixelProcessing processImage: viewImage]; //In this case the image is black
//imageToDisplay.image = viewImage; //In this case the image is black too
//imageToDisplay.image = [UIImage imageNamed: #"icon.png"]; //In this case image is being displayed properly
What am I doing wrong?
Thanks.
This one is also working quite good. Use it when the camera preview is open:
UIImage *viewImage = [[(id)objc_getClass("PLCameraController")
performSelector:#selector(sharedInstance)]
performSelector:#selector(_createPreviewImage)];
But as far as I found out it brings the same results than the following solution which takes a 'screenshot' of the current screen:
extern CGImageRef UIGetScreenImage();
CGImageRef cgoriginal = UIGetScreenImage();
CGImageRef cgimg = CGImageCreateWithImageInRect(cgoriginal, rect);
UIImage *viewImage = [UIImage imageWithCGImage:cgimg];
CGImageRelease(cgoriginal);
CGImageRelease(cgimg);
A problem I didn't still find a fix for is, how can one get the camera image very fast without any overlays?
The unofficial call is:
UIGetScreenImage()
which you declare above the #implementation as:
extern CGImageRef UIGetScreenImage();
There may be a documented way to do this in 3.1, but I'm not sure. If not, please please file a Radar with Apple asking them to make some kind of screen grab access public!!!
That uses your same AppleID you log in to the iPhone development portal with.
Update: This call is not yet documented, but Apple explicitly has given the OK to use it with App Store apps.
at least for now, there's no way to do this. (certainly no official documented way, and as far as I know nobody's figured out an unofficial way either.)
the camera preview data is being drawn by the OS in some way that bypasses the normal graphics methods.