如何使用node-webkit创建临时映像文件?

时间:2014-07-02 12:56:13

标签: image node.js node-webkit

我正在使用node-webkit开发应用程序以获取TIFF图像的一些数据。由于Webkit不支持TIFF图像,我想创建一个临时PNG版本以在应用程序中显示它。我怎么能这样做?在app.dataPath这样的node-webkit中是否有临时文件的方式或位置?或者我应该使用另一个节点模块node-temp

我很期待很快得到你的答案。谢谢。

2 个答案:

答案 0 :(得分:1)

您不需要创建临时图像文件,请尝试使用数据网址。

<h1>You will see an image later</h1>
<img id="img" src="">
<script type="text/javascript">
  //start js code here
  var data_prefix = "data:image/png;base64,";
  var img = document.getElementById('img');
  var xhr = new XMLHttpRequest();
  xhr.open('GET','https://avatars2.githubusercontent.com/u/1356417?s=140',true);
  xhr.responseType = 'arraybuffer';
  xhr.onload = function(e){
    var arr = new Uint8Array(this.response);
    var raw = String.fromCharCode.apply(null,arr);
    var b64=btoa(raw);
    var dataURL="data:image/jpeg;base64,"+b64;
    img.src = dataURL;
  };
  xhr.send();
</script>

答案 1 :(得分:0)

是的,如果您使用的是纯客户端解决方案,请考虑使用HTML5文件API。

This article让你了解。

当然,这是假设您正在操作客户端Javascript中的TIFF数据,并希望将其写入临时.png文件。