简体   繁体   English

HTML5 Canvas上下文globalAlpha无法处理图像[iOS]

[英]HTML5 Canvas context globalAlpha not working on image [iOS]

I'm updating the "this.opacity" value to fade an svg logo. 我正在更新“this.opacity”值以淡化svg徽标。 The code bellow is working except on iOS(8). 除了iOS(8)之外,代码正在工作。

    var size = (this.canvas.width * 0.2) * 0.4;

    this.context.save();
    this.context.globalAlpha = this.opacity;
    this.context.drawImage(this.svg, this.canvas.width * 0.04, this.canvas.width * 0.027, size, size);
    this.context.restore();

Animating the alpha of SVG images is not supported on iOS. iOS 支持动画化SVG图像的alpha。 But i found a solution. 但我找到了解决方案。 If you create a fullscreen canvas using the following code to scale it: 如果使用以下代码创建全屏画布以缩放它:

var ratio = window.devicePixelRatio || 1,
    width = $(window).width(),
    height = $(window).height();

this.canvas.width = width * ratio;
this.canvas.height = height * ratio;
this.canvas.style.width = width + "px";
this.canvas.style.height = height + "px";

this.update();

You will be able to use double sized images to give retina support, that way you don't have to use SVG elements in your canvas (which is IMHO terrible for your memory as well). 您将能够使用双倍大小的图像来提供视网膜支持,这样您就不必在画布中使用SVG元素(这对您的记忆来说也很糟糕)。 And the good thing is that images will accept setting the globalAlpha of your context. 好消息是图像将接受设置上下文的globalAlpha。

Hope the reader is informed enough :-). 希望读者充分了解情况:-)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM