Skip to main content

my.getImageInfo

getImageInfo

my.getImageInfo là API dùng để lấy thông tin của 1 ảnh (image). Ảnh có thể từ remote, từ đường dẫn cục bộ hoặc từ resources của app.

Quét mã để trải nghiệm

Xem code mẫu trên Tini Studio

Demo

Trải nghiệm thử với trình giả lập bên dưới

API Params

Thuộc tínhKiểu dữ liệuBăt buộcMô tả
srcstringĐường dẫn của ảnh. Hỗ trợ remote URL, đường dẫn tương đối, đường dẫn từ resources của app.
successFunctionCallback function khi lấy thông tin ảnh thành công
failFunctionCallback function khi lấy thông tin ảnh bất thành
completeFunctionCallback function khi gọi API hoàn tất bất kể việc lấy thông tin ảnh thành công hay thất bại.

Success function payload

Thuộc tínhKiểu dữ liệuMô tả
widthnumberChiều rộng của ảnh
heightnumberChiều cao của ảnh
orientationstringOrientation của ảnh
pathstringĐường dẫn cục bộ của ảnh
typestringĐịnh dạng của ảnh, ví dụ jpg, png

Orientation type

KiểuMô tả
upMặc định
downXoay 180°
leftXoay 90° ngược chiều kim đồng hồ
rightXoay 90° theo chiều kim đồng hồ
up-mirroredGiống up nhưng lật theo chiều ngang
down-mirroredGiống down nhưng lật theo chiều ngang
left-mirroredGiống left nhưng lật theo chiều dọc
right-mirroredGiống right nhưng lật theo chiều dọc

Sample Code

<view>
<block-header title="Usage" description="Get image info" />
<view class="block-content">
<view class="text">Remote Image: {{remoteUrl}}</view>
<view class="text">Local Resources: {{localResources}}</view>
</view>
<view class="block-content">
<button class="button-full" onTap="onFromRemoteImage">From Remote Image
</button>
<button class="button-full" onTap="onFromLocalImage">From Local
Image</button>
<button class="button-full" onTap="onFromResources">From
resources</button>
</view>
</view>
Page({
data: {
remoteUrl:
'https://salt.tikicdn.com/cache/w1240/ts/brickv2og/46/be/6f/dbc3e5d06f9f063d4b69c1cb7248d9fb.png.webp',
localResources: 'images/app_logo.png'
},
onFromRemoteImage() {
this.getImageInfo(this.data.remoteUrl);
},
onFromLocalImage() {
my.chooseImage({
count: 1,
success: (res) => {
this.getImageInfo(res.filePaths[0]);
},
fail: (e) => {
console.log(e);
}
});
},
onFromResources() {
this.getImageInfo(this.data.localResources);
},

getImageInfo(path) {
my.getImageInfo({
src: path,
success: (res) => {
console.log(res);
my.alert({
title: 'File Info',
content: JSON.stringify(res)
});
},
fail: (e) => {
console.log(e);
}
});
}
});