codecamp

百度智能小程序 获取图片信息

swan.getImageInfo

解释:获取图片信息

方法参数

Object object

object参数说明

属性名类型必填默认值说明

src

String

图片的路径,可以是相对路径、临时文件路径或存储文件路径、网络图片。

success

Function

接口调用成功的回调函数

fail

Function

接口调用失败的回调函数

complete

Function

接口调用结束的回调函数(调用成功、失败都会执行)

success 返回参数说明

参数类型说明

width

Number

图片宽度(单位:px)

height

Number

图片高度(单位:px)

path

String

返回图片的本地路径

orientation

String

返回图片的方向:
· up:默认不变;
· down:180 度旋转;
· left:逆时针 90 度旋转;
· right:顺时针 90 度旋转;
· up-mirrored:镜像翻转;
· down-mirrored:镜像 180 旋转;
· left-mirrored:逆时针 90 度镜像旋转;
· right-mirrored:顺时针 90 度镜像旋转。

type

String

返回图片的格式

示例


图片示例


代码示例 1: 绝对路径图片 

在开发者工具中打开

<view class="wrap">
    <view class="card-area">
        <image mode="aspectFill" class="display-area-image" src="https://b.bdstatic.com/miniapp/image/getImageInfo.png"></image>
        <view class="top-description border-bottom">图片信息</view>
        <view class="list-area border-bottom" s-for="item in infoList">
            <view class="list-item-key-4">{{item.chineseName}}}</view>
            <view class="list-item-value">{{item.value}}</view>
        </view>
    </view>
    <view class="swan-security-padding-bottom flex-button">
        <button type="primary" class="bottom-btn" bindtap="getImageInfo">获取图片信息</button>
    </view>
</view>

代码示例 2: 相对路径图片 
在开发者工具中打开

Page({
    getImageInfo() {
        swan.getImageInfo({
            src: '../images/ai.png',
            success: res => {
                console.log('getImageInfo success', res);
            },
            fail: err => {
                console.log('getImageInfo fail', err);
            }
        });
    }
});

代码示例 3: 临时文件路径 
在开发者工具中打开

<view class="wrap">
    <view class="card-area">
        <view class="top-description border-bottom">图片信息</view>
        <view class="list-area border-bottom" s-for="item in infoList">
            <view class="list-item-key-4">{{item.chinaName}}}</view>
            <view class="list-item-value">{{item.value}}</view>
        </view>
    </view>
    <view class="swan-security-padding-bottom flex-button">
        <button type="primary" class="bottom-btn" bindtap="getImageInfo">选择一张图片并获取信息</button>
    </view>
</view>

    错误码

    Android

    错误码说明

    201

    解析失败,请检查调起协议是否合法

    202

    解析失败,请检查参数是否正确

    1001

    执行失败

    iOS

    错误码说明

    202

    解析失败,请检查参数是否正确

    1003

    读取图片内容为空(小程序文件夹为空或读取图片失败)



    百度智能小程序 预览图片
    百度智能小程序 保存图片到系统相册
    温馨提示
    下载编程狮App,免费阅读超1000+编程语言教程
    取消
    确定
    目录

    百度智能小程序开发文档

    百度智能小程序 组件

    百度智能小程序 地图

    百度智能小程序 画布

    百度智能小程序 API

    百度智能小程序 界面

    百度智能小程序 关注小程序引导组件

    百度智能小程序 自定义组件

    百度智能小程序 媒体

    百度智能小程序 设备

    百度智能小程序 拨打电话

    百度智能小程序 内存警报

    百度智能小程序 手机联系人

    百度智能小程序 用户截屏事件

    百度智能小程序 第三方平台

    百度智能小程序 开放接口

    百度智能小程序 百度收银支付

    百度智能小程序 分包预下载

    百度智能小程序 数据分析

    百度智能小程序 服务端

    百度智能小程序 云开发

    百度智能小程序 初始化

    百度智能小程序 云函数

    百度智能小程序 服务端初始化

    百度智能小程序 服务器获取上下文

    百度智能小程序 服务端云函数

    百度智能小程序 开发教程

    百度智能小程序 功能开发

    百度智能小程序 基本原理

    百度智能小程序 小程序自动化

    百度智能小程序 视频教程

    关闭

    MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }