我举个例子:
<Dropzone
onDrop={this.handleDrop}
disableClick
style={{ width: '250px', height: '250px' }}>
<AvatarEditor
ref={this.refAvatar}
image={this.state.image}
borderRadius={125}
width={250}
height={250}
border={0}
scale={1}
/>
</Dropzone>
一切在编辑器中看起来都是正确的:
治疗:
handleDrop = dropped => {
this.setState({ image: dropped[0] })
};
onClickSave = () => {
// This returns a HTMLCanvasElement, it can be made into a data URL or a blob,
// drawn on another canvas, or added to the DOM.
const canvas = this.refAvatar.current.getImage();
// If you want the image resized to the canvas size (also a HTMLCanvasElement)
const canvasScaled = this.refAvatar.current.getImageScaledToCanvas();
const img = canvasScaled.toDataURL();
const rect = this.refAvatar.current.getCroppingRect();
};
结果,有canvasScaled
(这里是裁剪的方形图片)和rect
。
以及如何获得圆形图片?在他们的预览演示中,圆度是使用 css: 实现的border-radius: 52.5px;
。它不会帮助我获得一张圆形图片并将其发送到服务器。
创造了一个隐形的
canvas
。我发送到服务器。
现在处理是:
在服务器上,处理是微不足道的,有快递:
图片是圆形的: