i have written an App that takes screenshots. If the user enables this feature the app uses a background queue to take screenshots.
In iOS7 everything works fine but with iOS 8 there are only send white Screenshots to the server.
I use this method to take a screenshot:
CGImageRef cgScreen = UIGetScreenImage();
if (cgScreen) {
result = [UIImage imageWithCGImage:cgScreen];
CGImageRelease(cgScreen);
}
Does anyone have an idea to solve the problem?
Unfortunately I could not find the Apple's official documentation about the method UIGetScreenImage() but I have read so many stackoverflow entries saying that has been removed in iOS8 and especially iOS7 with 64bit binaries.
I am using following method to make screenshot and which is working from iOS 5 to iOS 8 without any problem.
- (void)makeScreenShotWithView:(UIView *)view scale:(float)scale {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, scale);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
if you want to make the whole screen as screenshot then pass a window object for an example view.window.
Try this
Related
I used the code below for years to be able to capture a screenshot of an UITableView (including hidden rows) and save it to the user's phone gallery or share it.
Since they updated to iOS 13 it doesn't work anymore, it captures only the visible part of the table leaving it blank on the bottom part.
-(UIImage *)imageFromCurrentTable
{
CGRect frame = self.tableView.frame;
frame.size.height = self.tableView.contentSize.height;
self.tableView.frame = frame;
UIGraphicsBeginImageContext(self.tableView.bounds.size);
[self.tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * data = UIImagePNGRepresentation(image);
return [UIImage imageWithData:data];
}
What changed in iOS 13? How this code can be updated? (the code is Obj-C but I will accept also swift answers!)
I have faced this issue. Due to cell Reuse, UIGraphicsGetImageFromCurrentImageContext cannot produce full UITableView structure.
One Way [Not Efficient Way]:
In cellForRowAtIndexPath, we can able to get which UITableViewCell using. Store that cell in [Int: UITableViewCell].
Get screenshot from UITableViewCell.contentView.
Add that screenshot's image as subview to UIView one by one.
Now, UIView having UITableView's contentView as Images.
Get screenshot from UIView.
thanks helping me I am poor in English.
Calling this method every 1 min from NSTimer. I need capture Activity happens in iPhone, not my application.... I tried with bellow code it will take my application screen.... I need to take iPhone screen short...
example user opens safari and types URLthen I need to take that screen capture from my app it is possible.
if it is possible how to achieve that.
if ([[UIScreen mainScreen] respondsToSelector:#selector(scale)]) {
UIGraphicsBeginImageContextWithOptions(self.window.bounds.size, NO, [UIScreen mainScreen].scale);
} else {
UIGraphicsBeginImageContext(self.window.bounds.size);
}
[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImagePNGRepresentation(image);
if (imageData) {
[imageData writeToFile:#"screenshot.png" atomically:YES];
} else {
NSLog(#"error while taking screenshot");
}
The Answer is NO.
Support for background execution must be declared in advance by the app that uses them.
Below are the Background modes for apps
Please read this link for more information : iOS BackgroundExecution
Now I work with UIImagePickerController and the crop image is a square.
this what I have now:
and this is what I want! it is possible?
There are a bunch of such "modules"/"libraries" available on GitHub for free. For example, the first match to the search I ran was:
https://github.com/myang-git/iOS-Image-Crop-View
You might find a suitable one.
You can use CGImageCreateWithImageInRect for Crop Images:
CGImageRef RefImage = CGImageCreateWithImageInRect([uncroppedImage CGImage], bounds);
UIImage *croppedImage = [UIImage imageWithCGImage:RefImage];
CGImageRelease(RefImage);
Does anyone has any idea how can I capture screen using objective c in mac os?
to be more specific, how can I capture the active / focused application screen then create an image into a specified path.
Any help is highly appreciated.
#Daniel,
You don't need to understand and implement the whole "Son of Grab". You just need the code below.
The following function will give you the screenshot
// This just invokes the API as you would if you wanted to grab a screen shot. The equivalent using the UI would be to
// enable all windows, turn off "Fit Image Tightly", and then select all windows in the list.
CGImageRef screenShot = CGWindowListCreateImage(CGRectInfinite, kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageDefault);
Use the following code to convert it to a NSImage
NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc] initWithCGImage:screenShot];
// Create an NSImage and add the bitmap rep to it...
NSImage *image = [[NSImage alloc] init];
[image addRepresentation:bitmapRep];
[bitmapRep release];
bitmapRep = nil;
Have you checked out Apple's “Son of Grab” for capturing images of windows with the CGWindow api?
You can also check Apple's OpenGLScreenSnapshot
I am trying to add a correct sized background image to support iPhone5 4" screen but i am still getting the same letterbox in the bottom. The image is correct sized image.
The code i use:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == kIphone5) {
//====THIS IS AN iPhone5 4" screen====//
UIImage *image = [UIImage imageNamed:#"iphone_frosty-568h#2x.png"];
[backgroundImage setImage:image];
}
I do have the lanch image in place..
UPDATE
I ended up adding the iPhone5 background image to the iPhone5 Storyboard and use that for all iPhone modes. Do not know if that is a correct way of doing this but it seems to work.
Can someone please advice?
Are you just talking about making your app run using the full screen on an iPhone 5 (getting rid of the letterbox)? If so, you don't use the new image size as a background image somewhere in code; you have to add it to your project file as a launch image. See the Launch Images section of the Apple docs for more info.