Quote:
Originally Posted by fladnag
I am all of a sudden getting the same problem as filharvey is. The code worked for a few days then suddenly stopped working.
I've tried two variations of the script as below and they both have the same results - "taking" a screen shot but adding only a white image to the photo library. Anyone have a guess as to what is going on?
Code:
//THIS WORKED THEN STOPPED WORKING
UIGraphicsBeginImageContext(self.window.bounds.size);
[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
//THIS IS NOT WORKING EITHER
CGRect screenRect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(screenRect.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(ctx, screenRect);
[self.window.layer renderInContext:ctx];
UIImage *screenImage = UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(screenImage, nil, nil, nil);
UIGraphicsEndImageContext();
|
i made a little modification and it is working here
Code:
CGRect contextRect = CGRectMake(50, 50, 200, 200);// whatever you need
UIGraphicsBeginImageContext(contextRect.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
But the resulting image is starting from origin (0,0) of screen whether I'm giving anything for x and y. But height and width are working as defined.
thanx for the code anyway...