【问题标题】:Image crop position with HTML5 Canvas使用 HTML5 Canvas 裁剪图像位置
【发布时间】:2018-10-23 14:06:34
【问题描述】:

我有一个 640 像素 x 480 像素的图像,并且我有坐标,我想在其中创建图像的画布裁剪。我对如何计算 1、裁剪尺寸、裁剪位置等感到有些困惑。

如何计算出正确的裁剪位置和裁剪尺寸?例如从坐标设置画布的大小,如下所示

coordinates = [160, 593, 345, 407] // [top, right, bottom, left]

基本上是我从 Python 脚本返回图像坐标,但不知道如何计算出正确的位置。

【问题讨论】:

    标签: html python-3.x canvas crop


    【解决方案1】:

    drawImage() 方法接受源坐标和目标坐标的参数。

     context.drawImage(imageObj, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight);
    

    【讨论】:

    • 谢谢你,我最终得到了作物的宽度和高度,这有帮助
    猜你喜欢
    • 2015-03-16
    • 2016-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-10
    • 2013-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多