小程序獲取圖片信息wx.getImageInfo
wx.getImageInfo(Object object)
獲取圖片信息。網絡圖片需先配置download域名才能生效。
參數
Object object
屬性 類型 默認值 必填 說明
src string 是 圖片的路徑,支持網絡路徑、本地路徑、代碼包路徑
success function 否 接口調用成功的回調函數
fail function 否 接口調用失敗的回調函數
complete function 否 接口調用結束的回調函數(調用成功、失敗都會執行)
object.success 回調函數
參數
Object res
屬性 類型 說明 最低版本
width number 圖片原始寬度,單位px。不考慮旋轉。
height number 圖片原始高度,單位px。不考慮旋轉。
path string 圖片的本地路徑
orientation string 拍照時設備方向 1.9.90
合法值 說明
up 默認方向(手機橫持拍照),對應 Exif 中的 1。或無 orientation 信息。
up-mirrored 同 up,但鏡像翻轉,對應 Exif 中的 2
down 旋轉180度,對應 Exif 中的 3
down-mirrored 同 down,但鏡像翻轉,對應 Exif 中的 4
left-mirrored 同 left,但鏡像翻轉,對應 Exif 中的 5
right 順時針旋轉90度,對應 Exif 中的 6
right-mirrored 同 right,但鏡像翻轉,對應 Exif 中的 7
left 逆時針旋轉90度,對應 Exif 中的 8
type string 圖片格式 1.9.90
示例代碼
wx.getImageInfo({
src: 'images/a.jpg',
success (res) {
console.log(res.width)
console.log(res.height)
}
})
wx.chooseImage({
success (res) {
wx.getImageInfo({
src: res.tempFilePaths[0],
success (res) {
console.log(res.width)
console.log(res.height)
}
})
}
})
- 小程序畫布Path2D
- Canvas 2D API 的接口 Path2D 用來聲明路徑,此路徑稍后會被CanvasRenderingContext2D 對象使用。
- 04-18 關注:1