Swift如何有效地每秒修改5000次大UIImage像素60次

问题描述

我有一个UIImageView及其图像myImage(=大UIImage 2000x2000)

我想每秒对此图像进行60次修改,每次约5000个新的不同像素(它们可以在图像中的任何位置,但通常每次都在图像的同一区域)

当前,我每秒使用UIGraphicsGetCurrentContext 60次以使用UIGraphicsGetImageFromCurrentImageContext绘制并保存新图像(请参见下面的代码)。

有没有更有效的方法?

var newpixels = [Smartpoint]()
... Fill newpixels with new pixels...

DispatchQueue.global().async
{
    self.myImage = self.drawOnImage(image :self.myImage,points: newpixels)                   
    DispatchQueue.main.async
    {
        self.myImageView.image = self.myImage
    }
}

...

func drawOnImage(image: UIImage,points : [Smartpoint]) -> UIImage? {

        autoreleasepool {

            UIGraphicsBeginImageContext(image.size)
     
            // Draw the starting image in the current context as background
            image.draw(at: CGPoint.zero)
            
            // Get the current context
            let context = UIGraphicsGetCurrentContext()!

            context.setBlendMode(.normal)

            for point in points
            {
                ... make something with the point ...
            }
            
            
            context.drawPath(using: .stroke) 
            
            // Save the context as a new UIImage
            let myImage = UIGraphicsGetImageFromCurrentImageContext()
            UIGraphicsEndImageContext()
            
            // Return modified image
            return myImage
        }
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...