本文介绍了流画布到imgITools使ico的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以在WinXP我一直很难把一个PNG文件转换为带画布的ICO。我发现这个方法 encodeImage 。我不知道它是否工作,但它看起来很有希望,但我不知道如何喂给我的画在 imgITools.decodeData 。 >

我应该使用 aImageStream 和/或 aMimeType ? / p>

  imgTools.decodeImageData(aImageStream,aMimeType,imgContainer); 

这是我的代码更多:

  img ['asdf']。file = new FileUtils.File(myPathHere); 

let iconStream;
try {
let imgTools = Cc [@ mozilla.org/image/tools;1]
.createInstance(Ci.imgITools);
let imgContainer = {value:null};

imgTools.decodeImageData(aImageStream,aMimeType,imgContainer);
iconStream = imgTools.encodeImage(imgContainer.value,
image / vnd.microsoft.icon,
format = bmp; bpp = 32);
} catch(e){
alert('failed converting icon'+ e)
throw(processIcon - Failure converting icon(+ e +));
}

let outputStream = FileUtils.openSafeFileOutputStream(img ['asdf']。file);
NetUtil.asyncCopy(iconStream,outStream,netutilCallback);


解决方案

,可能更容易使用以下canvas方法:




  • toDataURI / toDataURIHD

  • toBlob /

  • mozFetchAsStream



还有未记录的 -moz-parse-options:,例如 -moz-parse-options:format = bmp; bpp = 32 。 (ref-tests似乎依赖于它,所以它不会很快消失,我会想)。



所以,这里是一个例子, a ArrayBuffer

 (canvas.toBlobHD || canvas.toBlob) .call(canvas,function(b){
var r = new FileReader();
r.onloadend = function(){
// r.result包含ArrayBuffer。
;
r.readAsArrayBuffer(b);
},image / vnd.microsoft.icon,-moz-parse-options:format = bmp; bpp = 32

这里有一个更完整的创建一个256x256的BMP图标。



由于您可能想将数据提供给js-ctypes,因此ArrayBuffer非常好,因为您可以,或使用 OS.File将其写入文件


So on WinXP I have been having a hard time converting a PNG file to an ICO with canvas. I found this method encodeImage. I don't know if it works but it looks promising but I can't figure out how to feed the image I drew on a canvas into imgITools.decodeData.

What should I use for aImageStream and/or aMimeType?

imgTools.decodeImageData(aImageStream, aMimeType, imgContainer);

This is more of my code:

 img['asdf'].file = new FileUtils.File(myPathHere);

let iconStream;
try {
  let imgTools = Cc["@mozilla.org/image/tools;1"]
                    .createInstance(Ci.imgITools);
  let imgContainer = { value: null };

  imgTools.decodeImageData(aImageStream, aMimeType, imgContainer);
  iconStream = imgTools.encodeImage(imgContainer.value,
                                    "image/vnd.microsoft.icon",
                                    "format=bmp;bpp=32");
} catch (e) {
  alert('failure converting icon ' + e)
  throw("processIcon - Failure converting icon (" + e + ")");
}

let outputStream = FileUtils.openSafeFileOutputStream(img['asdf'].file);
NetUtil.asyncCopy(iconStream, outStream, netutilCallback);
解决方案

Since you're having a canvas already(?), it would be probably easier to use either on of the following canvas methods:

  • toDataURI/toDataURIHD
  • toBlob/toBlobHD
  • mozFetchAsStream

There is also the undocumented -moz-parse-options:, e.g -moz-parse-options:format=bmp;bpp=32. (ref-tests seem to depend on it, so it isn't going away anytime soon I'd think).

So, here is an example for loading stuff into an ArrayBuffer.

(canvas.toBlobHD || canvas.toBlob).call(canvas, function (b) {
    var r = new FileReader();
    r.onloadend = function () {
        // r.result contains the ArrayBuffer.
    };
    r.readAsArrayBuffer(b);
}, "image/vnd.microsoft.icon", "-moz-parse-options:format=bmp;bpp=32");

Here is a more complete example fiddle creating a 256x256 BMP icon.

Since you likely want to feed that data into js-ctypes, having an ArrayBuffer is great because you can create pointers from it directly, or write it to a file using OS.File.

这篇关于流画布到imgITools使ico的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 17:37