图片裁剪位置 HTML5 Canvas
Image crop position with HTML5 Canvas
我有一个 640px x 480px 的图像,我有坐标,我想在其中创建图像的 canvas 裁剪。我对如何计算 1、裁剪大小、裁剪位置等感到有点困惑。
如何计算出正确的裁剪位置和裁剪尺寸?例如canvas 从如下坐标
设置什么尺寸
coordinates = [160, 593, 345, 407] // [top, right, bottom, left]
基本上我从 Python 脚本返回图像坐标,但不知道如何计算出正确的位置。
drawImage() 方法接受源坐标和目标坐标的参数。
context.drawImage(imageObj, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight);
我有一个 640px x 480px 的图像,我有坐标,我想在其中创建图像的 canvas 裁剪。我对如何计算 1、裁剪大小、裁剪位置等感到有点困惑。
如何计算出正确的裁剪位置和裁剪尺寸?例如canvas 从如下坐标
设置什么尺寸coordinates = [160, 593, 345, 407] // [top, right, bottom, left]
基本上我从 Python 脚本返回图像坐标,但不知道如何计算出正确的位置。
drawImage() 方法接受源坐标和目标坐标的参数。
context.drawImage(imageObj, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight);