绘制下载的图标chrome扩展名

时间:2018-02-03 12:39:00

标签: canvas google-chrome-extension icons

我使用此示例从url设置扩展图标。

                                var img = new Image,
                                canvas = document.createElement("canvas"),
                                ctx = canvas.getContext("2d"),
                                src = settings['address'] + "/2.png"; // insert image url here

                                img.crossOrigin = "Anonymous";

                                img.onload = function() {
                                    canvas.width = img.width;
                                    canvas.height = img.height;
                                    ctx.drawImage( img, 0, 0 );
                                    chrome.browserAction.setIcon({"imageData" : ctx.getImageData(0,0,19,19)});

                                };

                                img.src = 'https://lh3.googleusercontent.com/krl72AYWGWgmhSCcdlHm-IgwkOBfdq6qVFIJtHxhfoSlMcrIgKdVhK-l-o800kv0m7uO=w300';

但最后我得到了一个愚蠢透明的图标,甚至不是图标而是虚空。没有错。

0 个答案:

没有答案