iOS上的WebP图像格式

问题描述 投票:6回答:4

我目前正在研究在我们的iOS软件中使用Google WebP图像格式的可能性。

我发现使用Google的C库将WebP解码为RGBA8888并不难。

但是,我想创建一个与UIImage相当的API和性能方面的实现。

Q1。在iOS中是否可以开发图像解码器,以便本机imageWithData和其他API读取新格式?

Q2。如果没有,UIImageView(和其他框架提供的控件)使用什么API绘制UIImage?是公开的(例如drawInRect / drawAtPoint)还是内部的?

我可以从UIImage继承,重写一些方法(例如+ imageWithContentsOfFile,+ imageWithData,+ imageNamed,-drawInRect,-drawAtPoint,并使我的WPImage对象在SDK提供的API中表现良好吗?

Q3。如果我假设的WPImage类的每个实例都将订阅UIApplicationDidReceiveMemoryWarningNotification(刷新RGBA图像缓冲区,将更小的原始WebP数据保留在RAM中),会不会对性能造成很大的损害?

我们正在开发的软件可能很容易在RAM中包含数百个不同的图像。

iphone ios uiimage image-formats webp
4个回答
2
投票

我为UIImage制作了完整的(解码/编码)WebP包装器。

https://github.com/shmidt/WebP-UIImage



0
投票

[我编写的另一个示例使用了卡森·麦当劳(Carson McDonald)开始但可重复使用的方式。基本上,您将WebP.framework添加到您的项目中(包括在我的示例中,或者可以使用Carson在其网站上的说明进行创建),然后您可以执行以下操作:

#import "UIImage+WebP.h"
...

self.imageView.image = [UIImage imageFromWebP:@"path/to/image.webp"];
// or
[self.button setImage:[UIImage imageFromWebP:@"path/to/image.webp" 
        forState:UIControlStateNormal]];

如果您想看一下我的示例,请转到此处:https://github.com/nyteshade/iOSWebPWithAlphaExample


0
投票

首先,将WebP像素解码到缓冲区中。然后,您需要调用CGDataProviderCreateWithData()为CoreGraphics创建一个“数据提供程序”,然后调用CGImageCreate()并传入提供程序和所有所需的参数。最后,调用UIImage imageWithCGImage:imageRef来创建UIImage实例。

© www.soinside.com 2019 - 2024. All rights reserved.