我有可以将图像上传到服务器的Web应用程序。我想裁剪并旋转图像,然后再发送到服务器。使用HTML 5 Canvas进行此操作的任何方法
是的,html canvas可以裁剪和旋转图像。
裁剪:使用context.drawImage的扩展属性。
context.drawImage(img,cropX,cropY,cropWidth,cropHeight,0,0,cropWidth,cropHeight);
旋转:使用context.rotate属性。
// set the point of rotation (example below sets rotation point at center-image)
context.translate(img.width/2,img.height/2);
// do the rotation (in radians)
context.rotate(radianAngle);
注意:除非您使用context.save/context.restore,否则所有转换(转换,旋转等)都是累积的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句