【发布时间】:2015-04-09 07:32:03
【问题描述】:
我正在开发一个跨平台的 cordova 项目,该项目涉及将图像上传到服务器并在网站上显示它们。从手机内存中获取resize后的图片并获取base64数据的代码如下:
var image = new Image();
image.src = URL;
image.onload = function () {
var canvas = document.createElement("canvas");
var img_width = this.width;
var img_height = this.height;
canvas.width =1000;
canvas.height = 1000;
var w=(1000/img_width);
var h=(1000/img_height);
var ctx = canvas.getContext("2d");
ctx.scale(w,h);
ctx.drawImage(this,0,0);
var dataURL = canvas.toDataURL("image/png",1);
这里的问题是,图像宽度设置为画布宽度但高度不是。 此外,该代码在 android 设备和 ipad 上完美运行,但问题仅出现在 iphone 上。
在 Iphone 4s 和 5c 上测试 谁能帮帮我!!!!
输入图像为:
画布上的图像输出(作为png文件)是:
【问题讨论】:
标签: ios iphone cordova html5-canvas base64