【问题标题】:How can I change the wallpaper on a Firefox OS device?如何更改 Firefox OS 设备上的壁纸?
【发布时间】:2014-05-26 03:33:20
【问题描述】:

我最近一直在学习 Firefox OS/B2G。我知道有大量的 API 可以从壁纸库中获取图像、更改设置和设置提醒(仅举几例)。但是,我完全不知道如何更换墙纸,或者,事实上,如果这是可能的。抱歉,如果这是一个愚蠢的问题。非常感谢。

【问题讨论】:

    标签: javascript api firefox firefox-os b2g


    【解决方案1】:

    您可以通过分享活动来做到这一点

    // imgToShare is the image you want to set as wallpaper
    var shareImage = document.querySelector("#share-image"),
        imgToShare = document.querySelector("#image-to-share");
    
    if (shareImage && imgToShare) {
        shareImage.onclick = function () {
            if(imgToShare.naturalWidth > 0) {
                // Create dummy canvas
                var blobCanvas = document.createElement("canvas");
                blobCanvas.width = imgToShare.width;
                blobCanvas.height = imgToShare.height;
    
                // Get context and draw image
                var blobCanvasContext = blobCanvas.getContext("2d");
                blobCanvasContext.drawImage(imgToShare, 0, 0);
    
                // Export to blob and share through a Web Activitiy
                blobCanvas.toBlob(function (blob) {
                    new MozActivity({
                        name: "share",
                        data: {
                            type: "image/*",
                            number: 1,
                            blobs: [blob]
                        }
                    });
                });
            }
            else {
                alert("Image failed to load, can't be shared");
            }
        };
    }
    

    您可以使用 Firefox OS 样板 https://github.com/robnyman/Firefox-OS-Boilerplate-App/ 测试一个实时示例。

    【讨论】:

    • 我会试试这个。非常感谢!
    • Frédéric- 我还没有机会测试这个,应该能在周末告诉你。再次感谢。
    猜你喜欢
    • 1970-01-01
    • 2019-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-04
    • 1970-01-01
    相关资源
    最近更新 更多