gpt4 book ai didi

ios - 在第 4 代 iPad 上缩放图像很慢,是否有更快的替代方案?

转载 作者:行者123 更新时间:2023-11-29 13:09:22 24 4
gpt4 key购买 nike

我正在尝试缩放和平移屏幕上的图像。

这是我的 drawRect:

- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextSetShouldAntialias(context, NO);
CGContextScaleCTM (context, senderScale, senderScale);
[self.image drawAtPoint:CGPointMake(imgposx, imgposy)];
CGContextRestoreGState(context);
}

senderScale为1.0时,移动图像(imgposx/imgposy)非常流畅。但是,如果 senderScale 有任何其他值,性能会受到很大影响,并且当我移动它时图像会断断续续。

我正在绘制的图像是一个 UIImage 对象。我用

创建它
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0);

并绘制一个简单的UIBezierPath(stroke):

self.image = UIGraphicsGetImageFromCurrentImageContext();  

我做错了什么吗?关闭抗锯齿并没有太大改善。

编辑:我试过这个:

rectImage = CGRectMake(0, 0, self.frame.size.width * senderScale, self.frame.size.height * senderScale);
[image drawInRect:rectImage];

但它和其他方法一样慢。

最佳答案

如果您希望它表现良好,您应该让 GPU 使用 CoreAnimation 来完成繁重的工作,而不是在 -drawRect: 方法中绘制图像。尝试创建一个 View 并执行以下操作:

myView.layer.contents = self.image.CGImage;

然后通过相对于其父 View 操作 UIView 来缩放和平移它。如果您在 -drawRect: 中绘制图像,您将使其完成为每一帧传输图像的艰苦工作。通过 CoreAnimation 只传输一次,然后让 GPU 缩放和平移图层。

关于ios - 在第 4 代 iPad 上缩放图像很慢,是否有更快的替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17752967/

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