ReactNative: 使用图片存储组件ImageStore组件

一、简介

ImageStore组件是ReactNative中用来存储图片的,支持通过uri从内存中获取和移除图片,也支持二进制图片的存储和获取。ImageStore组件提供的API就只有4个静态函数,使用起来比较简单。

二、API

1、通过uri获取图片

//查询图片,两个参数:第一个图片的uri,第二个为查询的回调
static hasImageForTag(uri: string, callback: (hasImage: bool) => void)

2、通过uri移除图片

//移除图片,一个参数,图片的uri
static removeImageForTag(uri: string)

3、存储图片的base64获取uri

//存储图片的base64编码,三个参数,第一个为图片的二进制编码、第二个为成功的回调、第三个为失败的回调。除非特殊需要,不推荐使用这种方式存储图片。很耗性能。
static addImageFromBase64( base64ImageData: string, success: (uri: string) => void, failure: (error: any) => void )

4、通过uri获取图片的base64

//通过图片的uri获取图片的base64编码,也是三个参数,第一个为图片的uri,第二个和第三个分别是成功和失败的回调,除非特殊需要,不推荐使用。很耗性能。
static getBase64ForTag( uri: string, success: (base64ImageData: string) => void, failure: (error: any) => void )

猜你喜欢

转载自www.cnblogs.com/XYQ-208910/p/12133067.html