reactjs - 裁剪的图像小于裁剪(Reactjs + react-image-crop)
问题描述
我正在尝试react-image-crop
在我的 React.JS 项目中实现。我有一个小问题:我裁剪的图像与我的裁剪尺寸不同。我在我的<ReactCrop>
组件上使用以下功能:
handleImageLoaded = (image) => {
//
};
handleOnCropChange = (percentCrop) => {
this.setState({ crop: percentCrop });
};
handleOnCropComplete = (percentCrop) => {
if (this.imageRef && percentCrop.width && percentCrop.height) {
const canvasRef = this.imagePreviewCanvasRef.current;
const { imgSrc } = this.state;
image64toCanvasRef(canvasRef, imgSrc, percentCrop);
}
};
这是我的image64toCanvasRef
功能:
export function image64toCanvasRef(canvasRef, image64, percentCrop) {
const canvas = canvasRef; // document.createElement('canvas');
canvas.width = percentCrop.width;
canvas.height = percentCrop.height;
const ctx = canvas.getContext('2d');
const image = new Image();
image.src = image64;
image.onload = function () {
ctx.drawImage(
image,
percentCrop.x,
percentCrop.y,
percentCrop.width,
percentCrop.height,
0,
0,
percentCrop.width,
percentCrop.height
);
};
}
所以我的猜测是问题在于ctx.drawImage()
解决方案
推荐阅读
- asp.net - EntityFramwork - 如何使用现有数据库并应用迁移,同时仍支持自动升级?
- javascript - 建立安全连接会延迟主页加载 (adsense)
- javascript - 如何将页面上某些元素的连接属性值作为字符串返回
- ios - 更新 PFObject 未按预期工作
- python - 熊猫:无法导入名称兼容
- c - 传递 C 字符串并将其与本地指针一起使用
- mysql - 如何查询最近日期并显示具体数据
- javascript - 如何正确删除表格单元格
- flutter - Flutter RenderFlex 在 Column Widget 内右侧溢出 15 个像素
- spring - Spring boot:使用 ServletUriComponentsBuilder 构建一个 uri“/{id}”