首页 > 解决方案 > Angular 9 ngx-image-cropper 使用滑块调整裁剪器大小

问题描述

ngx-image-cropper在我的项目中使用了一个库。我只想以 16/9 的纵横比裁剪图像,这没关系。我已设置aspectRatio为 16/9,裁剪器是矩形的。我还实现mat-slider了,它应该只改变图像裁剪器的宽度和高度,就像它与拖动裁剪器的箭头来缩放它一样。是否有可能将调整裁剪器大小的 mat-slider 事件添加到通过拖动箭头更改裁剪器比例时它是如何工作的?我不想用垫子滑块缩放图像,而只是裁剪器。我在ngx-image-cropper图书馆搜索过,但没有找到适合我需要的任何东西。谢谢你的帮助!

图书馆链接:https ://www.npmjs.com/package/ngx-image-cropper

    <div class="image-cropper-dimensions">
      <image-crop
        [imageFile]="data.file"
        [cropWidth]="sliderValue"
        [aspectRatio]="16 / 9"
        [isFileStrip]="true"
        [roundCropper]="data.isRoundedCropper"
        (onImageCropped)="onImageCropped($event)"
      >
      </image-crop>
    </div>
  </div>
  <div class="image-edit-container">
    <mat-slider
      [min]="SLIDER_MIN_VALUE"
      [color]="'primary'"
      [value]="sliderValue"
      [step]="SLIDER_STEP"
      (input)="onSliderChange($event)"
    >
    </mat-slider>

标签: angularcropper

解决方案


在我的应用程序中,我只使用以下命令更改和高度:[maintainAspectRatio]="false"

这是我的代码的一小部分:

<image-cropper
  [imageChangedEvent]="imageChangedEvent"
  [imageURL]="imageUrl"
  [transform]="transform"
  [maintainAspectRatio]="false"
  [aspectRatio]="aspectRatio"
  [canvasRotation]="canvasRotation"
  (imageCropped)="imageCropped($event)"
></image-cropper>


推荐阅读