media component image


WeChat applet image


Image resources

QQ截图20170208104341.png

##Note: The width of the image tag is 300px, Height 225px

mode has 13 modes, 4 of which are scaling modes and 9 are cropping modes.

QQ截图20170208104357.png

Crop mode

QQ截图20170208104412.png

##Example:

<view class="page">
  <view class="page__hd">
    <text class="page__title">image</text>
    <text class="page__desc">图片</text>
  </view>
  <view class="page__bd">
    <view class="section section_gap" wx:for-items="{{array}}" wx:for-item="item">
      <view class="section__title">{{item.text}}</view>
      <view class="section__ctn">
        <image style="width: 200px; height: 200px; background-color: #eeeeee;" mode="{{item.mode}}" src="{{src}}"></image>
      </view>
    </view>
  </view>
</view>
Page({
  data: {
    array: [{
      mode: 'scaleToFill',
      text: 'scaleToFill:不保持纵横比缩放图片,使图片完全适应'
    }, {
      mode: 'aspectFit',
      text: 'aspectFit:保持纵横比缩放图片,使图片的长边能完全显示出来'
    }, {
      mode: 'aspectFill',
      text: 'aspectFill:保持纵横比缩放图片,只保证图片的短边能完全显示出来'
    }, {
      mode: 'top',
      text: 'top:不缩放图片,只显示图片的顶部区域'
    }, {
      mode: 'bottom',
      text: 'bottom:不缩放图片,只显示图片的底部区域'
    }, {
      mode: 'center',
      text: 'center:不缩放图片,只显示图片的中间区域'
    }, {
      mode: 'left',
      text: 'left:不缩放图片,只显示图片的左边区域'
    }, {
      mode: 'right',
      text: 'right:不缩放图片,只显示图片的右边边区域'
    }, {
      mode: 'top left',
      text: 'top left:不缩放图片,只显示图片的左上边区域'
    }, {
      mode: 'top right',
      text: 'top right:不缩放图片,只显示图片的右上边区域'
    }, {
      mode: 'bottom left',
      text: 'bottom left:不缩放图片,只显示图片的左下边区域'
    }, {
      mode: 'bottom right',
      text: 'bottom right:不缩放图片,只显示图片的右下边区域'
    }],
    src: '../../resources/cat.jpg'
  },
  imageError: function(e) {
    console.log('image3发生error事件,携带值为', e.detail.errMsg)
  }
})
Original image

201609241558036306.jpgscaleToFill

Scale the image without maintaining the aspect ratio, making the image completely fit

201609241558161661.pngaspectFit

Maintain the aspect ratio Scale the image so that the long side of the image can be fully displayed

201609241558242948.pngaspectFill

Maintain the aspect ratio Zoom the image, only ensure that the short side of the image can be fully displayed

201609241558304918.pngtop

Do not scale the image, only display the top area of ​​the image

201609241558371029.pngbottom

Does not scale the image, only displays the bottom area of ​​the image

201609241558432174.pngcenter

No Zoom the image and only display the middle area of ​​the image

201609241558484868.pngleft

Do not zoom the image and only display the left area of ​​the image

201609241558522131.pngright

201609241558581927.pngtop left

Does not scale the image , only the upper left area of ​​the image is displayed

top right

Does not scale the image, only displays the upper right area of ​​the image

201609241559098551.png

bottom left

Does not scale the image, only displays the upper right area of ​​the image Display the lower left area of ​​the image

201609241559146074.png

bottom right

Do not zoom the image, only display the lower right area of ​​the image

201609241559199723.png