html5 显示tif,javascript - Loading tiff files into HTML5 canvas - Stack Overflow

I am trying to load .tif files onto an HTML5 canvas. After some research, I discovered that I might be able to do it using FileReader. Most of my code below is from http://www.nczonline.net/blog/2012/05/15/working-with-files-in-javascript-part-2/ . Unfortunately, the following test page fails on .tif files (it works on other image files) saying 'Image could not load' in Firefox and Chrome (let's ignore IE for this test). Am I missing something?

function loadFile(e) {

var file = e.target.files[0];

var reader = new FileReader();

reader.onload = function(event) {

var canvas = document.getElementById('myCanvas');

var context = canvas.getContext('2d');

var dataUri = event.target.result,

img = new Image();

// wait until the image has been fully processed

img.onload = function() {

context.drawImage(img, 0, 0);

};

img.onerror = function () {

console.error('Image could not load.');

}

img.src = dataUri;

};

reader.onerror = function(event) {

console.error("File could not be read. Code " + event.target.error.code);

};

reader.readAsDataURL(file);

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值