问题
I am having trouble getting a screen shot that is not blurry - first I tried this:
Screen capture for iOS
and it was not blurry but I think Apple will not let this code through - won't make the review?
so I went with the official solution in the developer docs: similar to this: Capturing Screen
But when I use the 'official' way, the image it creates is blurry
Here is the code I am using straight from the dev support docs (iOS6 and I am scaling it, but there is no difference if scale is 0):
CGSize imageSize = [[UIScreen mainScreen] bounds].size;
if (NULL != UIGraphicsBeginImageContextWithOptions)
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.65);
else
UIGraphicsBeginImageContext(imageSize);
CGContextRef context = UIGraphicsGetCurrentContext();
// Iterate over every window from back to front
for (UIWindow *window in [[UIApplication sharedApplication] windows])
{
if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen])
{
// -renderInContext: renders in the coordinate space of the layer,
// so we must first apply the layer's geometry to the graphics context
CGContextSaveGState(context);
// Center the context around the window's anchor point
CGContextTranslateCTM(context, [window center].x, [window center].y);
// Apply the window's transform about the anchor point
CGContextConcatCTM(context, [window transform]);
// Offset by the portion of the bounds left of and above the anchor point
CGContextTranslateCTM(context,
-[window bounds].size.width * [[window layer] anchorPoint].x,
-[window bounds].size.height * [[window layer] anchorPoint].y);
// Render the layer hierarchy to the current context
[[window layer] renderInContext:context];
// Restore the context
CGContextRestoreGState(context);
}
}
// Retrieve the screenshot image
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
回答1:
UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale)
allows you to create graphic bitmap context which supports high resolution screens by applying scale factor.
If you specify a value of 0.0 then the scale factor is set to the scale factor of the device’s main screen. On a standard-resolution screen, the scale factor is typically 1.0. On a high-resolution screen, the scale factor is typically 2.0.
In your case you specify the value of 0.65
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.65);
So some blurring effect occurs
You can get complete information about using scale factor in iOS Drawing Concepts Guide Points Versus Pixels
来源:https://stackoverflow.com/questions/16849944/ios-screen-capture-is-blurry