Javascript Cordova应用程序-JPEG(Base64)图像压缩为缩略图不适用于windows 8.1应用程序?
我正在尝试将JPEG(Base64)压缩成256x192的缩略图。但压缩后的图像显示为空白 下面是我的代码Javascript Cordova应用程序-JPEG(Base64)图像压缩为缩略图不适用于windows 8.1应用程序?,javascript,cordova,cross-platform,visual-studio-cordova,image-compression,Javascript,Cordova,Cross Platform,Visual Studio Cordova,Image Compression,我正在尝试将JPEG(Base64)压缩成256x192的缩略图。但压缩后的图像显示为空白 下面是我的代码 createWindowsThumbImage = function (name, type, data_url, callback) { var img, canvas, context, result, dataURL; img = document.createElement("img"); img.src = "data:image/jpeg;
createWindowsThumbImage = function (name, type, data_url, callback) {
var img, canvas, context, result, dataURL;
img = document.createElement("img");
img.src = "data:image/jpeg;base64," + data_url;
canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 192;
context = canvas.getContext("2d");
// Fill the canvas with white color to avoid the transperent behaviour of png images
context.fillStyle = "#FFFFFF";
context.fillRect(0, 0, 256, 192);
// Draw image with 256*192 dimention*/
context.drawImage(img, 0, 0, 256, 192);
dataURL = canvas.toDataURL(type);
result = getFileData(type, dataURL);
if (type === "image/jpeg") {
name = name.substr(0, name.lastIndexOf(".")) + ".256x192.jpg";
} else {
name = name.substr(0, name.lastIndexOf(".")) + ".256x192.png";
}
callback({name: name, type: type, data: result.file_data});
};
请您也发布
getFileData
function的代码好吗?@ElvisXia MSFTgetFileData=function(type,file_data){var content={};switch(type){case“image/jpeg”:content.file_data=file_data.substr(23);content.category=“image”;break;case“image/png”:content.file_data=file_data.substr(22);content.category=“image”;break;}返回content;}代码>我从代码中制作了一个示例,但没有重现问题。您是否添加了数据:image/jpeg;base64,
字符串到数据字符串的开头?例如:document.getElementById(“myImage”).src=“data:image/jpeg;base64”+result.data
@ElvisXia MSFT添加数据:image/jpeg;base64
code在windows选项卡或windows应用程序上运行良好,图像显示完美。但是,同样的代码在windows phone上显示空白屏幕。我无法复制这个。它在我的windows phone上运行良好。您能在模拟器或其他设备上试用吗?您能同时发布getFileData
function的代码吗?@ElvisXia MSFTgetFileData=function(type,file_data){var content={};switch(type){case“image/jpeg”:content.file\u data=file\u data.substr(23);content.category=“image”break;case“image/png”:content.file\u data=file\u data.substr(22);content.category=“image”break;}返回内容;}代码>我从代码中制作了一个示例,但没有重现问题。您是否添加了数据:image/jpeg;base64,
字符串到数据字符串的开头?例如:document.getElementById(“myImage”).src=“data:image/jpeg;base64”+result.data
@ElvisXia MSFT添加数据:image/jpeg;base64
code在windows选项卡或windows应用程序上运行良好,图像显示完美。但是,同样的代码在windows phone上显示空白屏幕。我无法复制这个。它在我的windows phone上运行良好。你能在模拟器或其他设备上试试吗?