How can I take screenshot when playing the video in MPMoviePlayer? I am using the below code for take screenshot but the player screen is black color.
1)
- (UIImage*)captureScreenshot:(UIView *)view {
CGRect screenRect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(screenRect.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:ctx];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, self, nil, nil);
return viewImage;
}
2) CGImageRef originalImage = UIGetScreenImage();
This is apple banned.
Please give any other way to get screenshot from the movie player. Please help me.
Somewhat hacktastic, but you could take a screenshot, grab a thumbnail from the movie player (e.g. as suggested here) and overlay the second on the first.
Related
I want to capture the screenshot for the transition between images.
- (UIImage *)captureView:(UIView *)view
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(screenRect.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(ctx, screenRect);
[view.layer.presentationLayer renderInContext:ctx];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
I call this method during a UIImageView playing transition of images, however, I just got the still image in the UIImageView but cannot capture the transition between images.
Anyone can help me out?
In the simulator you can hit shift 3 times to slow animation down, you might be able to catch the transition then.
I am merging two images and then I take a screenshot by applying this code:
UIGraphicsBeginImageContext(size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
img_AddText=viewImage;
[dragView removeFromSuperview];
imgV_SelectedImg.image=nil;
imgV_SelectedImg.image=img_AddText;
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
The problem is that when the final image loses its quality it blurs.
Try using the withOptions version of UIGraphicsBeginImageContext
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
i got the snapshot with good quality and particular location of screen. By this code.
-(UIImage *)takeScreenShot
{
CGRect grabRect;
grabRect = CGRectMake(0,70,320,260);
UIGraphicsBeginImageContextWithOptions(grabRect.size, self.view.opaque, 0.0);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(ctx, -grabRect.origin.x, -grabRect.origin.y);
[self.view.layer renderInContext:ctx];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;
}
it gives me excellent snapshot..
I've made a category on UIImage class that may help you. It goes like this:
+ (UIImage*)imageWithView:(UIView *)view opaque:(BOOL)opaque bgColor:(UIColor*)bgColor{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, opaque, [[UIScreen mainScreen] scale]);
if(!opaque){
[bgColor set];
}
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
It works fine for me. No bluring was detected. Try to use it. If you'll still have it then most likely the problem is in your saving code...
Cheers... :)
UIGraphicsBeginImageContextWithOptions(size, NO, 2.0);
this solve my prblem by increasing scale from 1.0 to 2.0
Did you provide an image for retina display? You should check it. You might be running in a simulator (in retina).
as per my title, i have a 2 picture which i will like to save it as one photo.
one of the photo allow user to gesture such as rotate, zoom and move around.
how do i save user moved and rotated picture ?
screen shot of the phone saved image
the code below are referred from
How to combine/ merge 2 images into 1
UIImage *image = nil;
CGSize newImageSize = CGSizeMake(cropImage.frame.size.width, cropImage.frame.size.height);
if (UIGraphicsBeginImageContextWithOptions != NULL) {
UIGraphicsBeginImageContextWithOptions(newImageSize, NO, [[UIScreen mainScreen] scale]);
} else {
UIGraphicsBeginImageContext(newImageSize);
}
// Draw image1
[maskImage.image drawInRect:CGRectMake(0,0, maskImage.frame.size.width,maskImage.frame.size.height)];
// Draw image2
[cropImage.image drawInRect:CGRectMake(cropImage.frame.origin.x, cropImage.frame.origin.y, cropImage.frame.size.width, cropImage.frame.size.height)];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
Try this piece of code
//Hide your views here like save button
CGRect screenRect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(screenRect.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, self, nil, nil);
//Show again your hidden views here like save button
I am implementing iphone application in which I want to implement below features.
When user touch on iphone screen then user snap shot will generate of touch area of the screen and save to photo library.
I have done googling but dont get successed.
Please help me for this query.
Thanks in advance
If you are looking for sample code to control the camera. Here is a bare bones Camera application that takes picture and saves it to library
Check out this method, pass the view touched to this method, will send u the image & save it to library.
- (UIImage*) giveScreentshotsOfView:(UIView*) view
{
if (view == nil)
return nil;
UIGraphicsBeginImageContext(view.bounds.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
+ (UIImage *) captureView:(UIView *)view
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(screenRect.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(ctx, screenRect);
[view.layer renderInContext:ctx];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//save the image to photo album
UIImageWriteToSavedPhotosAlbum(newImage, nil, nil , nil);
}
I want to take screenshot programatically. So that i write code for it like,
CGContextRef context = [self createBitmapContextOfSize:self.frame.size];
//not sure why this is necessary...image renders upside-down and mirrored
CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, self.frame.size.height);
CGContextConcatCTM(context, flipVertical);
[self.layer renderInContext:context];
CGImageRef cgImage = CGBitmapContextCreateImage(context);
UIImage* background = [UIImage imageWithCGImage: cgImage];
CGImageRelease(cgImage);
self.currentScreen = background;
Here all code is in custom UIView of UIViewController. Now when i play UIImageView png sequence animation on UIView, then i didn't get updated changes in UIImageView which is subview of custom UIView, why? I got only result is UIImageView with first UIImage.
Basically i need to create an video of my game play like talking tom application.
Take the screenshot of your ImageView with something like this:
[[[yourImageView layer] presentationLayer] renderInContext:context];
Use NSTimer for calling that getScreenshot function.
Hope this helps
you should probably take a look at AVFoundation and specifically AVAssetWriter as a way of creating videos of your screen content.
Following code is use for the capture the image into the iPhone for that following code to be use.
CGRect rect = CGRectMake(0.0, 0.0,self.view.frame.size.width,self.view.frame.size.height-44);
NSValue *rectObj = [NSValue valueWithCGRect:rect];
CGRect rectRestored = [rectObj CGRectValue];
UIGraphicsBeginImageContext(CGSizeMake(rectRestored.size.width, rectRestored.size.height-44));
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
Also store the image into the gallery.