使用Mozactivity Firefox操作系统将预先准备好的图像用作壁纸
Use a prepended image as wallpaper using Mozactivity Firefox OS
我想从网络上获取一个图像,并将其设置为Firefox操作系统设备上的壁纸。
到目前为止,我已经尝试了两种方法,
$(document).on( 'click', '#share-image', function() {
walp = new Image()
walp.onload = function () {
var walCanvas = document.createElement('canvas');
walCanvas.width = walp.width;
walCanvas.height = walp.height;
var walCtx = walCanvas.getContext('2d');
walCtx.drawImage(walp,0,0);
walCanvas.toBlob( function (walBlob) {
var Activitiy = new MozActivity({
name: 'share',
data: {
type: 'image/*',
number: 1,
blobs: [walBlob]
}
});
});
};
walp.src = image; //image is the link to jpeg.
});
而这个。。。
var shareImage = document.querySelector("#share-image"),
imgToShare = document.querySelector('#prependedImage');
alert(imgToShare);
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");
}
};
}
两者都适用于本地保存的图像,但不适用于从远程位置获取的图像。
我也尝试过以下方法。
var pre = '<img width="100%" data-l10n-id="prependedImage" id="prependedImage" src="'+image+'" />';
$('#image1').prepend(pre);
和
$('#prependedImage').attr('src',image);
两者都可以,但都不会显示壁纸菜单,除非它是本地保存的图像。我是javascript的新手,如果能给我一个解释代码示例问题的答案,我将不胜感激。谢谢
你能试试这样的东西吗:
var xhr = new XMLHttpRequest({
mozSystem: true
});
xhr.open("GET", "http://25.media.tumblr.com/4751d1eccf9311ee0e05bdff819a7248/tumblr_n2yxzxzxr81rsg8blo1_250.png", true);
xhr.responseType = "blob";
xhr.onload = function () {
//sample activity
var activity = new MozActivity({
name: "share",
data: {
type: "image/*",
number:1,
blobs: [this.response],
filenames:["wallpapertest.png"]
},
});
};
xhr.onerror = function () {
alert("Error with System XHR");
};
xhr.send();
您还需要将应用程序设置为特权,并在清单中添加systemxhr权限:
"permissions": {
"systemXHR": {}
},
"type": "privileged"
相关文章:
- 在jquery文档准备好之前加载Modernizr
- 请求准备一个文件并返回路径,允许用户在准备好时下载
- Electron:Express.js服务器在Mongo数据库'It’准备好了
- 从Document调用onchange函数.已准备好从更新中预先选择的项目
- jquery触发器可以从点击开始工作,但没有准备好
- 我怎么知道Jqgrid已经准备好了
- Javascript+HTML中的日期选择器准备好了吗?(需要:DD、MM、YY的单独字段加上日历选择器)
- 创建元素更好还是只在html上准备好它们
- 如何移除预先准备好的容器
- 加载直到图像准备好,而图像隐藏直到它准备好
- 将参数传递到准备好文档的.js文件
- 如何一次插入两个表?准备好的发言
- 将不同大小的图像很好地拼接成拼贴画
- 使用Mozactivity Firefox操作系统将预先准备好的图像用作壁纸
- Jquery滑块加载图像时,准备好了占位符
- jQuery/Javascript -运行函数前(文档).准备好加载图像
- 如何在文档准备好和图像加载后调用函数
- 如何加载花哨的盒子图像到浏览器缓存后,文档准备好了
- 用javascript预加载图像并在准备好时显示
- 如何让javascript执行只是当dom和css准备好了,而不是图像