Shotcut插件-背景不透明度

时间:2018-10-21 15:57:04

标签: html canvas opacity

我正在使用带有Shotcut的html插件来生成视频。 我想在画中画一个圆形的画框。

我的问题是,如何使背景透明。 默认背景为黑色,并且该填充会覆盖剪贴区域之外的视频。

我正在使用以下html。

<html>
<head>
<style type="text/css">
html, body {
    width: 100%;
    height: 100%;
    margin: 0;
}
</style>
<script type="text/javascript">
function Filter() {
    // Create a canvas
    this.canvas = document.createElement('canvas');
    this.canvas.width = window.innerWidth;
    this.canvas.height = window.innerHeight;
    document.body.appendChild(this.canvas);
    this.context = this.canvas.getContext('2d');

    // Set the document backgrouind color.
    var color = webvfx.getStringParameter('color');
    if (!color)
        color = 'black';
    document.body.bgColor = color;

    // Clip video to a circle in the middle of the canvas
    this.radius = webvfx.getNumberParameter('radius');
    if (!this.radius)
        this.radius = 0.5;
    this.context.beginPath();
    this.context.arc(this.canvas.width/2, this.canvas.height/2,
                     this.canvas.height * this.radius, 0, Math.PI*2, true)
    this.context.clip();

    this.image = new Image();
    this.n = 0
}

Filter.prototype.render = function(time) {
    var color = webvfx.getStringParameter('color')
    if (color && color != document.body.bgColor)
        document.body.bgColor = color;

    var radius = webvfx.getNumberParameter('radius')
    if (radius && radius != this.radius) {
        this.radius = radius;

        // Clear/reset the canvas
        this.canvas.width = this.canvas.width;

        this.context.beginPath();
        this.context.arc(this.canvas.width/2, this.canvas.height/2,
                         this.canvas.height * this.radius, 0, Math.PI*2, true)
        this.context.clip();
    }
    webvfx.getImage("video").assignToHTMLImageElement(this.image);
    this.context.drawImage(this.image, 0, 0);
}

function init() {
    var filter = new Filter();
    webvfx.renderRequested.connect(filter, Filter.prototype.render);
    webvfx.imageTypeMap = { "video" : webvfx.SourceImageType };
    webvfx.readyRender(true);
}
window.addEventListener("load", init, false);
</script>
</head>
<body>
</body>
</html>

0 个答案:

没有答案