相关疑难解决方法(0)

用JavaScript获取图像数据?

我有一个带有一些图像的常规HTML页面(只是常规的<img />HTML标签).我想得到他们的内容,优选base64编码,而不需要重新下载图像(即它已经被浏览器加载,所以现在我想要内容).

我很想用Greasemonkey和Firefox实现这一目标.

javascript firefox base64 greasemonkey image

326
推荐指数
6
解决办法
41万
查看次数

在JavaScript中将blob对象改为base64

我正在尝试实现一个粘贴处理程序来从用户的剪贴板中获取图像.我希望这只能在Google Chrome上运行,我并不担心其他浏览器.

这是我在互联网上找到的一种方法的一部分,我正在努力调整它.

// Get the items from the clipboard
var items = e.clipboardData.items;
    if (items) {
    // Loop through all items, looking for any kind of image
        for (var i = 0; i < items.length; i++) {
            if (items[i].type.indexOf("image") !== -1) {
                // We need to represent the image as a file,
                var blob = items[i].getAsFile();
                // and use a URL or webkitURL (whichever is available to the browser)
                // to create a temporary URL to the object
                var …
Run Code Online (Sandbox Code Playgroud)

javascript base64 google-chrome blob image

24
推荐指数
1
解决办法
3万
查看次数

BlobBuilder破坏二进制数据

我有BlobBuilder(Chrome11)的问题我尝试从服务器获取XHR请求的图像.然后我尝试使用BlobBuilder/FileWriter将其保存到本地FS.互联网上的每个例子都是关于使用text/plain mime类型,这些例子工作得很好.但是当我尝试编写使用XHR获得的二进制数据时,文件大小变为原始文件大小的1.5-2倍.它无法在Picasa/Eye of Gnome中查看.

var xhr = new XMLHttpRequest();
var photoOrigUrl = 'http://www.google.ru/images/nav_logo72.png';
xhr.open('GET', photoOrigUrl, true);
xhr.onreadystatechange = function() {
    if (xhr.readyState == 4 && xhr.status == 200) {
        var contentType = xhr.getResponseHeader('Content-type');

        fsLink.root.getFile('nav_logo72.png', {'create': true}, function(fileEntry) {
            fileEntry.createWriter(function(fileWriter) {
                var BlobBuilderObj = new (window.BlobBuilder || window.WebKitBlobBuilder)();
                BlobBuilderObj.append(xhr.responseText);

                fileWriter.write(BlobBuilderObj.getBlob(contentType));
            }, function(resultError) {
                console.log('writing file to file system failed (   code ' + resultError.code + ')');
            });
        });
    }
}

xhr.send();
Run Code Online (Sandbox Code Playgroud)

fsLink存在,这是扩展.

javascript html5 blob google-chrome-extension

7
推荐指数
1
解决办法
7045
查看次数