{"id":31441,"date":"2024-11-25T13:17:10","date_gmt":"2024-11-25T05:17:10","guid":{"rendered":"https:\/\/fwq.ai\/blog\/31441\/"},"modified":"2024-11-25T13:17:10","modified_gmt":"2024-11-25T05:17:10","slug":"%e5%b0%8f%e7%a8%8b%e5%ba%8f%e4%bd%bf%e7%94%a8-getimageinfo%e8%8e%b7%e5%8f%96%e5%9b%be%e7%89%87%e4%bf%a1%e6%81%af","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/31441\/","title":{"rendered":"\u5c0f\u7a0b\u5e8f\u4f7f\u7528.getImageInfo()\u83b7\u53d6\u56fe\u7247\u4fe1\u606f"},"content":{"rendered":"<p style=\"text-align: left\">\u8fd9\u6b21\u7ed9\u5927\u5bb6\u5e26\u6765\u5c0f\u7a0b\u5e8f\u4f7f\u7528.getImageInfo()\u83b7\u53d6\u4fe1\u606f\uff0c\u5c0f\u7a0b\u5e8f\u4f7f\u7528.getImageInfo()\u83b7\u53d6\u56fe\u7247\u4fe1\u606f\u7684\u6709\u54ea\u4e9b\uff0c\u4e0b\u9762\u5c31\u662f\u5b9e\u6218\u6848\u4f8b\uff0c\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u3002<\/p>\n<p style=\"text-align: left\">\u672c\u6587\u5b9e\u4f8b\u4e3a\u5927\u5bb6\u5206\u4eab\u4e86\u4e5d\u5bab\u683c\u56fe\u7247\u5c55\u793a\u7684\u5177\u4f53\u4ee3\u7801\uff0c\u4f9b\u5927\u5bb6\u53c2\u8003\uff0c\u5177\u4f53\u5185\u5bb9\u5982\u4e0b<\/p>\n<p style=\"text-align: left\"><strong>\u4e00.\u77e5\u8bc6\u70b9<\/strong><\/p>\n<p style=\"text-align: left\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/061\/021\/719c764d0c12a2bf99654f3008dfc806-0.jpg\" class=\"aligncenter\" title=\"\u5c0f\u7a0b\u5e8f\u4f7f\u7528.getImageInfo()\u83b7\u53d6\u56fe\u7247\u4fe1\u606f\u63d2\u56fe\" alt=\"\u5c0f\u7a0b\u5e8f\u4f7f\u7528.getImageInfo()\u83b7\u53d6\u56fe\u7247\u4fe1\u606f\u63d2\u56fe\" \/><\/p>\n<p style=\"text-align: left\"><strong>\u4e8c.\u5217\u5b50<\/strong><\/p>\n<p style=\"text-align: left\">(1).\u52a0\u8f7d\u65f6<\/p>\n<pre>&lt;view class=\"zn-uploadimg\"&gt;  \r\n  &lt;image src=\"{{tempFilePaths}}\" mode=\"aspecFill\" style=\"width: 100%; height: 450rpx\" \/&gt;  \r\n  &lt;text&gt;\u56fe\u7247\u7684\u5927\u5c0f\uff1a{{imgwidth}}px*{{imgheight}}px&lt;\/text&gt; \r\n&lt;\/view&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<pre>var app = getApp()  \r\nPage({ \r\n  data: {  \r\n    tempFilePaths: '..\/uploads\/foods.jpg', \r\n    imgwidth:0, \r\n    imgheight:0,  \r\n  }, \r\n  onReady:function(){ \r\n    \/\/ \u9875\u9762\u6e32\u67d3\u5b8c\u6210  \r\n    var _this = this;  \r\n    wx.getImageInfo({ \r\n      src: _this.data.tempFilePaths, \r\n      success: function (res) { \r\n        _this.setData({ \r\n          imgwidth:res.width, \r\n          imgheight:res.height, \r\n        }) \r\n      } \r\n    })  \r\n  }  \r\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"text-align: left\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/061\/021\/719c764d0c12a2bf99654f3008dfc806-1.jpg\" class=\"aligncenter\" title=\"\u5c0f\u7a0b\u5e8f\u4f7f\u7528.getImageInfo()\u83b7\u53d6\u56fe\u7247\u4fe1\u606f\u63d2\u56fe1\" alt=\"\u5c0f\u7a0b\u5e8f\u4f7f\u7528.getImageInfo()\u83b7\u53d6\u56fe\u7247\u4fe1\u606f\u63d2\u56fe1\" \/><\/p>\n<p style=\"text-align: left\">(2).\u4e0a\u4f20\u56fe\u7247\u65f6<\/p>\n<pre>&lt;view class=\"zn-uploadimg\"&gt; \r\n  &lt;button type=\"primary\"bindtap=\"chooseimage\"&gt;\u83b7\u53d6\u56fe\u7247&lt;\/button&gt;  \r\n  &lt;image src=\"{{tempFilePaths}}\" mode=\"aspecFill\" style=\"width: 100%; height: 450rpx\"\/&gt;  \r\n  &lt;text&gt;\u56fe\u7247\u7684\u5927\u5c0f\uff1a{{imgwidth}}px*{{imgheight}}px&lt;\/text&gt; \r\n&lt;\/view&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<pre>.zn-uploadimg{ \r\n  padding:1rem; \r\n} \r\n.zn-uploadimg image{ \r\n  margin:1rem 0; \r\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<pre>var app = getApp()  \r\nPage({ \r\n  data: {  \r\n    tempFilePaths: '',  \r\n    imgwidth:0, \r\n    imgheight:0, \r\n  }, \r\n  \/**  \r\n   * \u4e0a\u4f20\u56fe\u7247 \r\n   *\/ \r\n  chooseimage: function () {  \r\n    var _this = this;  \r\n    wx.chooseImage({  \r\n      count: 1, \/\/ \u9ed8\u8ba49  \r\n      sizeType: ['original', 'compressed'], \/\/ \u53ef\u4ee5\u6307\u5b9a\u662f\u539f\u56fe\u8fd8\u662f\u538b\u7f29\u56fe\uff0c\u9ed8\u8ba4\u4e8c\u8005\u90fd\u6709  \r\n      sourceType: ['album', 'camera'], \/\/ \u53ef\u4ee5\u6307\u5b9a\u6765\u6e90\u662f\u76f8\u518c\u8fd8\u662f\u76f8\u673a\uff0c\u9ed8\u8ba4\u4e8c\u8005\u90fd\u6709  \r\n      success: function (res) {  \r\n        \/\/ \u8fd4\u56de\u9009\u5b9a\u7167\u7247\u7684\u672c\u5730\u6587\u4ef6\u8def\u5f84\u5217\u8868\uff0ctempFilePath\u53ef\u4ee5\u4f5c\u4e3aimg\u6807\u7b7e\u7684src\u5c5e\u6027\u663e\u793a\u56fe\u7247  \r\n        _this.setData({  \r\n          tempFilePaths:res.tempFilePaths  \r\n        })  \r\n        wx.getImageInfo({ \r\n          src: res.tempFilePaths[0], \r\n          success: function (res) { \r\n            _this.setData({ \r\n              imgwidth:res.width, \r\n              imgheight:res.height, \r\n            }) \r\n          } \r\n        })  \r\n      }  \r\n    })  \r\n  }  \r\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"text-align: left\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/061\/021\/9e2424c047d7f14ce1c2f11ce808ee13-2.jpg\" class=\"aligncenter\" title=\"\u5c0f\u7a0b\u5e8f\u4f7f\u7528.getImageInfo()\u83b7\u53d6\u56fe\u7247\u4fe1\u606f\u63d2\u56fe2\" alt=\"\u5c0f\u7a0b\u5e8f\u4f7f\u7528.getImageInfo()\u83b7\u53d6\u56fe\u7247\u4fe1\u606f\u63d2\u56fe2\" \/><\/p>\n<p>\u76f8\u4fe1\u770b\u4e86\u672c\u6587\u6848\u4f8b\u4f60\u5df2\u7ecf\u638c\u63e1\u4e86\u65b9\u6cd5\uff0c\u66f4\u591a\u7cbe\u5f69\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n<p>\u63a8\u8350\u9605\u8bfb\uff1a<\/p>\n<p><\/p>\n<p><\/p>\n<p><\/p>\n<p><\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5c0f\u7a0b\u5e8f\u4f7f\u7528.getImageInfo()\u83b7\u53d6\u56fe\u7247\u4fe1\u606f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u6b21\u7ed9\u5927\u5bb6\u5e26\u6765\u5c0f\u7a0b\u5e8f\u4f7f\u7528.getImageInfo()\u83b7\u53d6\u4fe1\u606f\uff0c\u5c0f\u7a0b\u5e8f\u4f7f\u7528.getImageInfo()\u83b7\u53d6\u56fe\u7247\u4fe1\u606f\u7684\u6709\u54ea\u4e9b\uff0c\u4e0b\u9762\u5c31\u662f\u5b9e\u6218\u6848\u4f8b\uff0c\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u3002 \u672c\u6587\u5b9e\u4f8b\u4e3a\u5927\u5bb6\u5206\u4eab\u4e86\u4e5d\u5bab\u683c\u56fe\u7247\u5c55\u793a\u7684\u5177\u4f53\u4ee3\u7801\uff0c\u4f9b\u5927\u5bb6\u53c2\u8003\uff0c\u5177\u4f53\u5185\u5bb9\u5982\u4e0b \u4e00.\u77e5\u8bc6\u70b9 \u4e8c.\u5217\u5b50 (1).\u52a0\u8f7d\u65f6 &lt;view class=&#8221;zn-uploadimg&#8221;&gt; &lt;image src=&#8221;{{tempFilePaths}}&#8221; mode=&#8221;aspecFill&#8221; style=&#8221;width: 100%; height: 450rpx&#8221; \/&gt; &lt;text&gt;\u56fe\u7247\u7684\u5927\u5c0f\uff1a{{imgwidth}}px*{{imgheight}}px&lt;\/text&gt; &lt;\/view&gt; \u767b\u5f55\u540e\u590d\u5236 var app = getApp() Page({ data: { tempFilePaths: &#8216;..\/uploads\/foods.jpg&#8217;, imgwidth:0, imgheight:0, }, onReady:function(){ \/\/ \u9875\u9762\u6e32\u67d3\u5b8c\u6210 var _this = this; wx.getImageInfo({ src: _this.data.tempFilePaths, success: function (res) { _this.setData({ imgwidth:res.width, imgheight:res.height, }) } }) } }) \u767b\u5f55\u540e\u590d\u5236 (2).\u4e0a\u4f20\u56fe\u7247\u65f6 &lt;view [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-31441","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31441","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=31441"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31441\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=31441"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=31441"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=31441"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}