亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

ReactCrop 使用原始分辨率裁剪圖像,而不是使用 CSS 更改分辨率

ReactCrop 使用原始分辨率裁剪圖像,而不是使用 CSS 更改分辨率

HUX布斯 2023-10-30 15:57:59
上傳和顯示的圖像的寬度是通過使用max-width:100%;ReactCrop裁剪原始圖像來改變的。我嘗試更改圖像寬度,使其隨容器寬度自動調整,但反應圖像裁剪十字線不會適應它,而是根據以前的分辨率裁剪圖像。在我附加的圖像中,您可以看到裁剪部分的圖像沒有出現在裁剪預覽中。它顯示的是原始分辨率的裁剪預覽。import React from "react";import ReactCrop from "react-image-crop";import { Button } from "antd";import "./custom-crop.scss";import {  image64toCanvasRef,  extractImageFileExtensionFromBase64,  base64StringtoFile,  downloadBase64File} from "./reusableUtils";class ImageUploader extends React.Component {  constructor(props) {    super(props);    this.imagePreviewCanvasRef = React.createRef();    this.state = {      isVerified: false,      imgSrc: null,      imgSrcExt: null,      crop: {        aspect: 1 / 1,        unit: "px", // default, can be 'px' or '%'        x: 130,        y: 50,        width: 200,        height: 200      }    };  }  onChange(e) {    let currFile = e[0];    let fileReader = new FileReader();    fileReader.addEventListener(      "load",      () => {        this.setState({          imgSrc: fileReader.result        });      },      false    );    fileReader.readAsDataURL(currFile);  }  handleOnCropChange = crop => {    this.setState({ crop: crop });  };  handleImageLoaded = () => {    // console.log(image);  };  handleOnCropComplete = crop => {    //console.log(crop, pixelCrop)    const canvasRef = this.imagePreviewCanvasRef.current;    const { imgSrc } = this.state;    // const imageData64 = canvasRef.toDataURL("image/" + fileExtension);    const fileExtension = extractImageFileExtensionFromBase64(imgSrc);    const fileName = "profile_pic." + fileExtension;    const myNewCrop = base64StringtoFile(imgSrc, fileName);    this.setState({ imgSrcExt: myNewCrop });    image64toCanvasRef(canvasRef, imgSrc, crop);  };
查看完整描述

1 回答

?
LEATH

TA貢獻1936條經驗 獲得超7個贊

使用百分比而不是像素。像這樣的東西。

 onCropChange={(crop, percentCrop) =>
                    this.setState({ crop: percentCrop })
                  }


查看完整回答
反對 回復 2023-10-30
  • 1 回答
  • 0 關注
  • 143 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號