【问题标题】:How to create a temporary image file with node-webkit?如何使用 node-webkit 创建临时图像文件?
【发布时间】:2014-07-02 12:56:12
【问题描述】:
我正在使用 node-webkit 开发一个应用程序来获取 TIFF 图像的一些数据。由于 webkit 不支持 TIFF 图像,我想创建一个临时 PNG 版本以在应用程序中显示它。我怎么能这样做? node-webkit中的临时文件有没有办法或地方,比如App.dataPath?或者我应该使用另一个节点模块node-temp?
我非常期待尽快得到您的答复。谢谢。
【问题讨论】:
标签:
image
node.js
node-webkit
【解决方案1】:
您不需要创建临时图像文件,请尝试数据 URL。
<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>
【解决方案2】:
是的,如果您追求纯客户端解决方案,请考虑使用 HTML5 文件 API。
This article 为您服务。
当然,这是假设您在客户端 Javascript 中操作 TIFF 数据,并希望将其写入临时 .png 文件。