🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# .toTempFilePathSync ### Canvas.toTempFilePathSync(Object object) Canvas.toTempFilePath 的同步版本 #### 参数 ##### Object object 属性类型默认值是否必填说明支持版本xnumber0否截取 canvas 的左上角横坐标ynumber0否截取 canvas 的左上角纵坐标widthnumbercanvas 的宽度否截取 canvas 的宽度heightnumbercanvas 的高度否截取 canvas 的高度destWidthnumbercanvas 的宽度否目标文件的宽度,会将截取的部分拉伸或压缩至该数值destHeightnumbercanvas 的高度否目标文件的高度,会将截取的部分拉伸或压缩至该数值fileTypestringpng否目标文件的类型qualitynumber1.0否jpg图片的质量,仅当 fileType 为 jpg 时有效。取值范围为 0.0(最低)- 1.0(最高),不含 0。不在范围内时当作 1.0**object.fileType 的合法值** 值说明jpgjpg 文件pngpng 文件#### 示例代码 Canvas.toTempFilePath ``` <pre class="prettyprint"><ol class="linenums"><li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln">canvas</span><span class="pun">.</span><span class="pln">toTempFilePath</span><span class="pun">({</span></code></li> <li class="l1"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> x</span><span class="pun">:</span><span class="pln"> </span><span class="lit">10</span><span class="pun">,</span></code></li> <li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> y</span><span class="pun">:</span><span class="pln"> </span><span class="lit">10</span><span class="pun">,</span></code></li> <li class="l1"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> width</span><span class="pun">:</span><span class="pln"> </span><span class="lit">200</span><span class="pun">,</span></code></li> <li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> height</span><span class="pun">:</span><span class="pln"> </span><span class="lit">150</span><span class="pun">,</span></code></li> <li class="l1"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> destWidth</span><span class="pun">:</span><span class="pln"> </span><span class="lit">400</span><span class="pun">,</span></code></li> <li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> destHeight</span><span class="pun">:</span><span class="pln"> </span><span class="lit">300</span><span class="pun">,</span></code></li> <li class="l1"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> success</span><span class="pun">:</span><span class="pln"> </span><span class="pun">(</span><span class="pln">res</span><span class="pun">)</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="pun">></span><span class="pln"> </span><span class="pun">{</span></code></li> <li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> wx</span><span class="pun">.</span><span class="pln">shareAppMessage</span><span class="pun">({</span></code></li> <li class="l1"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> imageUrl</span><span class="pun">:</span><span class="pln"> res</span><span class="pun">.</span><span class="pln">tempFilePath</span></code></li> <li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> </span><span class="pun">})</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> ``` Canvas.toTempFilePathSync ``` <pre class="prettyprint"><ol class="linenums"><li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln">let tempFilePath </span><span class="pun">=</span><span class="pln"> canvas</span><span class="pun">.</span><span class="pln">toTempFilePathSync</span><span class="pun">({</span></code></li> <li class="l1"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> x</span><span class="pun">:</span><span class="pln"> </span><span class="lit">10</span><span class="pun">,</span></code></li> <li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> y</span><span class="pun">:</span><span class="pln"> </span><span class="lit">10</span><span class="pun">,</span></code></li> <li class="l1"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> width</span><span class="pun">:</span><span class="pln"> </span><span class="lit">200</span><span class="pun">,</span></code></li> <li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> height</span><span class="pun">:</span><span class="pln"> </span><span class="lit">150</span><span class="pun">,</span></code></li> <li class="l1"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> destWidth</span><span class="pun">:</span><span class="pln"> </span><span class="lit">400</span><span class="pun">,</span></code></li> <li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> destHeight</span><span class="pun">:</span><span class="pln"> </span><span class="lit">300</span></code></li> <li class="l1"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pun">})</span></code></li> <li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln">wx</span><span class="pun">.</span><span class="pln">shareAppMessage</span><span class="pun">({</span></code></li> <li class="l1"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> imageUrl</span><span class="pun">:</span><span class="pln"> tempFilePath</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/render/canvas/Canvas.toTempFilePathSync.html>