# gdip.webp 库模块帮助文档

## gdip 成员列表 <a id="gdip" href="#gdip">&#x23;</a>

### gdip.webp() <a id="gdip.webp" href="#gdip.webp">&#x23;</a>
[返回对象:GdipWebPObject](#GdipWebPObject)

### gdip.webp(bitmap) <a id="gdip.webp" href="#gdip.webp">&#x23;</a>
参数 @bitmap 指定 gdip.bitmap 对象。

### gdip.webp(source,hint) <a id="gdip.webp" href="#gdip.webp">&#x23;</a>
参数 @source 可指定图像文件路径或内存数据。  
可选用参数 @hint 指定文件后缀名，默认为 "*.webp"（强制按 WebP 解析）  
支持 gdip.bitmap 支持的所有格式以及 webp 格式。  
与 gdip.bitmap 相似，如果在当前界面线程提前导入 inet.http 库，  
则 @source 参数也可以指定图像网址。

## gdip.webp 成员列表 <a id="gdip.webp" href="#gdip.webp">&#x23;</a>

WebP 编码与解析器。  
此支持库要求 aardio 版本大于 v40.54.2。  
导入此库后 gdip.bitmap 与 plus 控件可自动识别 .webp 后缀的图像。  

此支持库的所有函数指定输入输出图像参数时都支持 GDI+ 支持的所有图像格式以及 WebP 格式。  

aardio 仍然建议使用 GDI+ 原生支持的 png,jpg,gif 等格式。  
可避免不必要的转换。  
或者也可以使用原生支持 WebP 格式的 web.view 浏览器组件。

创建 WebP 编码与解析器对象。  
gdip.webp 对象作为 gdip.bitmap 的构造参数可转换为 gdip.bitmap 对象。  
gdip.webp 对象赋值为 plus 控件的背景图像（background）或前景图像（foreground）时  
会自动转换为 gdip.bitmap 对象。

### gdip.webp.compress(imageData,quality) <a id="gdip.webp.compress" href="#gdip.webp.compress">&#x23;</a>
压缩 WebP   
参数 @imageData 指定 WebP 图像内存数据。  
参数 @quality 可指定值: 0~100 或 -1（无损），省略则默认为 80。

### gdip.webp.decode(source,asBgra) <a id="gdip.webp.decode" href="#gdip.webp.decode">&#x23;</a>
解码 WebP 图像。  
参数 @source 可指定 *.webp 格式图像文件路径或内存数据。  
可选参数 asBgra 指定为 true 则强制输出 BGRA 格式。  
成功返回像数数据 getInfo 方法返回的图像信息。  
失败返回 null,错误信息。

### gdip.webp.encode(pixelBuffer,width,height,options) <a id="gdip.webp.encode" href="#gdip.webp.encode">&#x23;</a>
编码像素为 Web 图像。  
参数 @pixelBuffer 指定图像数据。  
参数 @width,@height 分别指定图像宽度和高度。  
参数 @options 用表对象指定选项，可包含 `alpha;stride;quality` 等字段。  
@options.quality 字段: 0~100 或 -1（无损），省略则默认为 80.

### gdip.webp.encodeBitmapToWebp(bmp,quality) <a id="gdip.webp.encodeBitmapToWebp" href="#gdip.webp.encodeBitmapToWebp">&#x23;</a>
gdip.bitmap 对象转换为 WebP 格式图像数据，返回 buffer 类型字节串。

### gdip.webp.encodeImageToWebp(data,quality) <a id="gdip.webp.encodeImageToWebp" href="#gdip.webp.encodeImageToWebp">&#x23;</a>
任意图像转换为 WebP 格式图像数据，返回 buffer 类型字节串。

### gdip.webp.getInfo() <a id="gdip.webp.getInfo" href="#gdip.webp.getInfo">&#x23;</a>
获取 WebP 图像信息。  
参数 @1 可指定 *.webp 格式图像文件路径或内存数据。  
成功返回包含width,height,alpha,animation,format,stride 字段的表对象。  
失败返回 null,错误信息

[返回对象:GdipWebPFeaturesObject](#GdipWebPFeaturesObject)

### gdip.webp.getVersion() <a id="gdip.webp.getVersion" href="#gdip.webp.getVersion">&#x23;</a>
获取 libwebp 版本号

### gdip.webp.is() <a id="gdip.webp.is" href="#gdip.webp.is">&#x23;</a>
检测参数 @1 指定的图像数据是否为 WebP 格式.  
参数 @1 可以是字节串（ buffer  类型）或字符串（string 类型）。

### gdip.webp.save(source,savePath,quality) <a id="gdip.webp.save" href="#gdip.webp.save">&#x23;</a>
保存为 WebP 文件。  
参数 @source 可指定图像文件路径或内存数据。  
参数 @path 指定保存路径。  
参数 @quality 可指定值: 0~100 或 -1（无损），省略则默认为 80。

### gdip.webp.toBitmap() <a id="gdip.webp.toBitmap" href="#gdip.webp.toBitmap">&#x23;</a>
将参数 @1 指定的 *.webp 格式图像文件路径或内存数据转换为 gdip.bitmap 对象。

[返回对象:gdipbitmapObject](https://www.aardio.com/zh-cn/docs/library-reference/gdip/bitmap.html#gdipbitmapObject)

## GdipWebPFeaturesObject 成员列表 <a id="GdipWebPFeaturesObject" href="#GdipWebPFeaturesObject">&#x23;</a>

### GdipWebPFeaturesObject.alpha <a id="GdipWebPFeaturesObject.alpha" href="#GdipWebPFeaturesObject.alpha">&#x23;</a>
是否有透明通道 (0/1)

### GdipWebPFeaturesObject.animation <a id="GdipWebPFeaturesObject.animation" href="#GdipWebPFeaturesObject.animation">&#x23;</a>
是否为动图 (0/1)

### GdipWebPFeaturesObject.format <a id="GdipWebPFeaturesObject.format" href="#GdipWebPFeaturesObject.format">&#x23;</a>
编码格式: 1=lossy, 2=lossless

### GdipWebPFeaturesObject.height <a id="GdipWebPFeaturesObject.height" href="#GdipWebPFeaturesObject.height">&#x23;</a>
图像高度

### GdipWebPFeaturesObject.stride <a id="GdipWebPFeaturesObject.stride" href="#GdipWebPFeaturesObject.stride">&#x23;</a>
扫描线字节宽度

### GdipWebPFeaturesObject.width <a id="GdipWebPFeaturesObject.width" href="#GdipWebPFeaturesObject.width">&#x23;</a>
图像宽度

## GdipWebPObject 成员列表 <a id="GdipWebPObject" href="#GdipWebPObject">&#x23;</a>

### GdipWebPObject.getBitmap() <a id="GdipWebPObject.getBitmap" href="#GdipWebPObject.getBitmap">&#x23;</a>
获取 Bitmap 对象

[返回对象:gdipbitmapObject](https://www.aardio.com/zh-cn/docs/library-reference/gdip/bitmap.html#gdipbitmapObject)

### GdipWebPObject.getInfo() <a id="GdipWebPObject.getInfo" href="#GdipWebPObject.getInfo">&#x23;</a>
获取图像信息

[返回对象:GdipWebPFeaturesObject](#GdipWebPFeaturesObject)

### GdipWebPObject.save(savePath,quality) <a id="GdipWebPObject.save" href="#GdipWebPObject.save">&#x23;</a>
保存图像。  
参数 @savePath 指定文件路径，后缀名指定为 ".webp" 则保存为 WebP 格式。  
也支持保存为 gdip.bitmap 支持的所有格式。

### GdipWebPObject.saveToBuffer(quality,hint) <a id="GdipWebPObject.saveToBuffer" href="#GdipWebPObject.saveToBuffer">&#x23;</a>
获取 WebP 图像数据。  
参数 quality 指定图像质量，可指定 0~100 或  -1(无损)，默认为 80。  
可选用参数 @hint 指定保存图像格式，默认为 "*.webp"
