<tfoot id='6MIlU'></tfoot>
      <bdo id='6MIlU'></bdo><ul id='6MIlU'></ul>
    <legend id='6MIlU'><style id='6MIlU'><dir id='6MIlU'><q id='6MIlU'></q></dir></style></legend>

    <small id='6MIlU'></small><noframes id='6MIlU'>

    1. <i id='6MIlU'><tr id='6MIlU'><dt id='6MIlU'><q id='6MIlU'><span id='6MIlU'><b id='6MIlU'><form id='6MIlU'><ins id='6MIlU'></ins><ul id='6MIlU'></ul><sub id='6MIlU'></sub></form><legend id='6MIlU'></legend><bdo id='6MIlU'><pre id='6MIlU'><center id='6MIlU'></center></pre></bdo></b><th id='6MIlU'></th></span></q></dt></tr></i><div id='6MIlU'><tfoot id='6MIlU'></tfoot><dl id='6MIlU'><fieldset id='6MIlU'></fieldset></dl></div>

      HTML5 画布上的图像渐变

      Image gradient on HTML5 canvas(HTML5 画布上的图像渐变)
      <legend id='mxD2w'><style id='mxD2w'><dir id='mxD2w'><q id='mxD2w'></q></dir></style></legend>
      • <bdo id='mxD2w'></bdo><ul id='mxD2w'></ul>
            <tfoot id='mxD2w'></tfoot>

            <small id='mxD2w'></small><noframes id='mxD2w'>

            <i id='mxD2w'><tr id='mxD2w'><dt id='mxD2w'><q id='mxD2w'><span id='mxD2w'><b id='mxD2w'><form id='mxD2w'><ins id='mxD2w'></ins><ul id='mxD2w'></ul><sub id='mxD2w'></sub></form><legend id='mxD2w'></legend><bdo id='mxD2w'><pre id='mxD2w'><center id='mxD2w'></center></pre></bdo></b><th id='mxD2w'></th></span></q></dt></tr></i><div id='mxD2w'><tfoot id='mxD2w'></tfoot><dl id='mxD2w'><fieldset id='mxD2w'></fieldset></dl></div>

              <tbody id='mxD2w'></tbody>

              1. 本文介绍了HTML5 画布上的图像渐变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想在图像上获得径向渐变效果(alpha = 1 在中间,在边缘透明).

                I would like to obtain a radial gradient effect on an image (alpha = 1 in the middle and transparent on the edges).

                你有什么想法吗?

                推荐答案

                如果我没记错你想做的是:

                If I'm not mistaking what you want to do is:

                1. 绘制图像
                2. 在其上绘制径向渐变,其中边框透明,中间不透明,并使用上下文中的 globalCompositeOperation 设置将透明渐变与图像混合.
                1. Draw the image
                2. Draw a radial gradient over it, where the borders are transparent and the middle is opaque and using the globalCompositeOperation setting on the context to blend the transparency gradient with the image.

                您可以很容易地将其转换为代码:http://jsfiddle.net/W8Ywp/1/.

                You can rather easily translate this into code: http://jsfiddle.net/W8Ywp/1/.

                var ctx = $('#cv').get(0).getContext('2d');
                
                var img = new Image();
                
                img.src = 'http://www.netstate.com/states/'
                        + 'symb/flowers/images/oklahoma_rose.jpg';
                
                img.onload = function() {
                    ctx.drawImage(img, 0, 0, 300, 300); // Draw image
                
                    // Create gradient, from middle to borders
                    var gradient = ctx.createRadialGradient(150, 150, 0,
                                                            150, 150, 150);
                
                    // Opaque white in the middle
                    gradient.addColorStop(0, 'rgba(255,255,255,0)');
                
                    // Transparent white at the borders
                    gradient.addColorStop(1, 'rgba(255,255,255,1)');
                
                    ctx.globalCompositeOperation = 'destination-out';
                    ctx.fillStyle = gradient;
                    ctx.fillRect(0, 0, 300, 300); // Fill rectangle over image with the gradient
                };
                

                这篇关于HTML5 画布上的图像渐变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How does object-fit work with canvas element?(对象适合如何与画布元素一起使用?)
                How to make rooftext effect and valley text effect in HTML5 (or Fabric.js)(如何在 HTML5(或 Fabric.js)中制作屋顶文字效果和山谷文字效果)
                Draw border around nontransparent part of image on canvas(在画布上的图像不透明部分周围绘制边框)
                dragging and resizing an image on html5 canvas(在 html5 画布上拖动图像并调整其大小)
                What#39;s the difference between a boolean as primitive and a boolean as property of an object?(作为原始对象的布尔值和作为对象属性的布尔值有什么区别?)
                I want to do animation of an object along a particular path(我想沿特定路径对对象进行动画处理)
                <i id='ZnV6l'><tr id='ZnV6l'><dt id='ZnV6l'><q id='ZnV6l'><span id='ZnV6l'><b id='ZnV6l'><form id='ZnV6l'><ins id='ZnV6l'></ins><ul id='ZnV6l'></ul><sub id='ZnV6l'></sub></form><legend id='ZnV6l'></legend><bdo id='ZnV6l'><pre id='ZnV6l'><center id='ZnV6l'></center></pre></bdo></b><th id='ZnV6l'></th></span></q></dt></tr></i><div id='ZnV6l'><tfoot id='ZnV6l'></tfoot><dl id='ZnV6l'><fieldset id='ZnV6l'></fieldset></dl></div>
                <tfoot id='ZnV6l'></tfoot>
                • <legend id='ZnV6l'><style id='ZnV6l'><dir id='ZnV6l'><q id='ZnV6l'></q></dir></style></legend>
                    <tbody id='ZnV6l'></tbody>

                  1. <small id='ZnV6l'></small><noframes id='ZnV6l'>

                      <bdo id='ZnV6l'></bdo><ul id='ZnV6l'></ul>