Skip to main content
Version: v3

Image Convert

The "Device App" can not show png images due to the limitation of device. The image can be shown normally after converting by image module.

image module

convert

Converting png images to image formats supported by the "Device App".

Types

(options: Options) => Promise<Result>

Parameters

Options: object

PropertyDescriptionRequiredType
filePathPath to the image that needs to be convertedYESstring
targetFilePathIf not filled, the rule for the path of the converted image is ${filePath}_converted. For example given the filePath value data://1.png, the converted path is data://1.png_convertedNOstring

Result: object

PropertyDescriptionType
filePathOriginal Image Pathstring
targetFilePathConverted Image Pathstring
optionsImage Conversion InformationResultOption

ResultOption: object

PropertyDescriptionType
sizeConverted file size in bytesnumber

Code Example

AppSideService({
onInit() {
image
.convert({
filePath: 'data://download/test.png'
})
.then((result) => {
console.log(reslut.targetFilePath) // data://download/test.png_converted
})

image
.convert({
filePath: 'data://download/test.png',
targetFilePath: 'data://download/converted_test.png'
})
.then((result) => {
console.log(reslut.targetFilePath) // data://download/converted_test.pang
})
}
})