# uni.getImageInfo(options)

获取图片信息 GitCode GitHub

# getImageInfo 兼容性

Web 微信小程序 Android iOS HarmonyOS
4.0 4.41 4.18 4.25 4.61

# 参数

名称 类型 必填 默认值 兼容性 描述
options GetImageInfoOptions -
-
名称 类型 必备 默认值 兼容性 描述
src string.ImageURIString -
图片的路径,可以是相对路径,临时文件路径,存储文件路径,网络图片路径
success (callback: GetImageInfoSuccess) => void -
接口调用成功的回调函数
fail (callback: IMediaError) => void -
接口调用失败的回调函数
complete (callback: any) => void -
接口调用结束的回调函数(调用成功、失败都会执行)

# GetImageInfoSuccess 的属性值

名称 类型 必备 默认值 兼容性 描述
width number -
图片宽度,单位px
height number -
图片高度,单位px
path string -
返回图片的本地路径
orientation string -
返回图片的方向
合法值 兼容性 描述
up
-
-
down
-
-
left
-
-
right
-
-
up-mirrored
-
-
down-mirrored
-
-
left-mirrored
-
-
right-mirrored
-
-
type string -
返回图片的格式

# IMediaError 的属性值

名称 类型 必备 默认值 兼容性 描述
errCode number -
-
错误码
合法值 兼容性 描述
1101001
-
用户取消
1101002
-
urls至少包含一张图片地址
1101003
-
文件不存在
1101004
-
图片加载失败
1101005
-
未获取权限
1101006
-
图片或视频保存失败
1101007
-
图片裁剪失败
1101008
-
拍照或录像失败
1101009
-
图片压缩失败
1101010
-
其他错误
errSubject string -
-
统一错误主题(模块)名称
data any -
-
错误信息中包含的数据
cause Error -
-
源错误信息,可以包含多个错误,详见SourceError
errMsg string -
-

# 参见

# 示例

hello uni-app x

扫码体验(手机浏览器跳转到App直达页)

Template

Script

<template>
  <!-- #ifdef APP -->
  <scroll-view style="flex:1">
  <!-- #endif -->
    <page-head :title="title"></page-head>
    <view class="uni-padding-wrap">
      <view class="uni-title">
        <text class="uni-subtitle-text">获取本地相对路径图片信息</text>
      </view>
      <image class="image" :src="relativeImagePath" mode="aspectFit"></image>
      <text class="margin-top-10">{{absoluteImageInfo}}</text>
      <view class="uni-title">
        <text class="uni-subtitle-text">获取网络路径图片信息</text>
      </view>
      <image class="image" :src="remoteImagePath" mode="aspectFit"></image>
      <text class="margin-top-10">{{remoteImageInfo}}</text>
      <view class="uni-title">
        <text class="uni-subtitle-text">获取本地绝对路径图片信息</text>
      </view>
      <image class="image" :src="absoluteImagePath" mode="aspectFit"></image>
      <text class="margin-top-10">{{relativeImageInfo}}</text>
      <view class="uni-btn-v">
        <button type="primary" @click="chooseImage">拍摄照片或从相册中选择照片</button>
      </view>
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>



<style>
  .image {
    align-self: center;
  }

  .margin-top-10 {
    margin-top: 10px;
  }
</style>

# 通用类型

# GeneralCallbackResult

名称 类型 必备 默认值 兼容性 描述
errMsg string -
错误信息