💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# wx.chooseImage ### wx.chooseImage(Object object) 从本地相册选择图片或使用相机拍照。 #### 参数 ##### Object object 属性类型默认值是否必填说明支持版本countnumber9否最多可以选择的图片张数sizeTypeArray.<string>\['original', 'compressed'\]否所选的图片的尺寸sourceTypeArray.<string>\['album', 'camera'\]否选择图片的来源successfunction否接口调用成功的回调函数failfunction否接口调用失败的回调函数completefunction否接口调用结束的回调函数(调用成功、失败都会执行)**object.sizeType 的合法值** 值说明original原图compressed压缩图**object.sourceType 的合法值** 值说明album从相册选图camera使用相机###### object.success 回调函数 **参数** **Object res** 属性类型说明支持版本tempFilePathsArray.<string>图片的本地临时文件路径列表tempFilesArray.<Object>图片的本地临时文件列表>= 1.2.0**res.tempFiles 的结构** 属性类型说明支持版本pathstring本地临时文件路径sizenumber本地临时文件大小,单位 B#### 示例代码 ``` <pre class="prettyprint"><ol class="linenums"><li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln">wx</span><span class="pun">.</span><span class="pln">chooseImage</span><span class="pun">({</span></code></li> <li class="l1"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> count</span><span class="pun">:</span><span class="pln"> </span><span class="lit">1</span><span class="pun">,</span></code></li> <li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> sizeType</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">'original'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'compressed'</span><span class="pun">],</span></code></li> <li class="l1"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> sourceType</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">'album'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'camera'</span><span class="pun">],</span></code></li> <li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> success </span><span class="pun">(</span><span class="pln">res</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></code></li> <li class="l1"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> </span><span class="com">// tempFilePath可以作为img标签的src属性显示图片</span></code></li> <li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> </span><span class="kwd">const</span><span class="pln"> tempFilePaths </span><span class="pun">=</span><span class="pln"> res</span><span class="pun">.</span><span class="pln">tempFilePaths</span></code></li> <li class="l1"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> </span><span class="pun">}</span></code></li> <li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pun">})</span></code></li> </ol> ``` > 原文: <https://developers.weixin.qq.com/minigame/dev/api/media/image/wx.chooseImage.html>