gpt4 book ai didi

iphone - iOS 中的像素化过渡

转载 作者:可可西里 更新时间:2023-11-01 05:31:38 24 4
gpt4 key购买 nike

如何实现像 this 这样的像素化过渡? (动画 gif)在 iOS 中?

是否可以用Core Animation来实现?

最佳答案

C4 - Travis 的评论是正确的,您最好的选择可能是自己实时渲染动画。您需要获取 QA1703 中的代码用于屏幕捕获,但调整您在 UIGraphicsBeginImageContextWithOptions 中创建的上下文的大小,并在调用 UIGraphicsGetCurrentContext 后立即适本地更改 Core Graphics 当前变换矩阵 (CTM)。所以,只要在我写这篇文章的时候打字,你的调整就会导致类似这样的结果:

- (UIImage*)screenshotWithScale:(CGFloat)scale
{
// Create a graphics context with the target size
// On iOS 4 and later, use UIGraphicsBeginImageContextWithOptions to take the scale into consideration
// On iOS prior to 4, fall back to use UIGraphicsBeginImageContext
CGSize imageSize = [[UIScreen mainScreen] bounds].size;

/* YOU'VE ADDED: */
imageSize.width *= scale;
imageSize.height *= scale;

if (NULL != UIGraphicsBeginImageContextWithOptions)
/* ... then stuff as per the original, down to ... */

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextScaleCTM(context, scale, scale);

// Iterate over every window from back to front
for (UIWindow *window in [[UIApplication sharedApplication] windows])
/* etc, etc, down to... */

// Retrieve the screenshot image
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

CGContextRestoreGState(context);
UIGraphicsEndImageContext();

return image;
}

使用 scale = 1.0,您将得到一个与屏幕完全相等的 UIImage。使用 scale = 0.5,您将获得横向和向下像素数的一半,使用 scale = 0.25,您将获得横向和向下像素数的四分之一,等等。

然后您可以将该 UIImage 放入 UIImageView 中,并将其图层的放大过滤器设置为 kCAFilterNearest。显示 ImageView 应该给你一个故意像素化的原始版本。然后你可以懒惰,继续对屏幕上已经显示的内容执行一半大小的渲染(所以第一次是实时 View ,随后是 ImageView )或者调整代码而不是从主窗口渲染,而是从指定的窗口渲染根据需要从原始 View 层次结构中查看和重新呈现(如果您想做一些事情而不是继续将比例除以整数,这将起作用)。

关于iphone - iOS 中的像素化过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9885460/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com