【发布时间】:2013-11-27 13:18:55
【问题描述】:
我遇到了一个问题,不知道下一步该尝试什么。
在我的应用程序中,我为我的用户提供了一个选择,即拍摄照片或从图库中选择照片。这部分工作正常,问题出现在照片的保存\阅读上。让我们从相机调用的角度来看。
function startCameraApp() {
PhotoTaken = false;
blackberry.event.addEventListener("onChildCardClosed", sharePhoto);
blackberry.invoke.invoke({
target: "sys.camera.card"
}, onInvokeSuccess, onInvokeError);
}
在 sharePhoto 中我有以下代码...
function sharePhoto(request) {
var image = new Image();
image.src = "file://" + request.data;
image.onload = function () {
// Now here I need to read the image file and convert it into base64.
var resized = resizeMe(image); // the resizeMe function is given below and it simply makes my image smaller
var imagedata = resized.split("base64,");
sessionStorage.setItem("MyNewPicture", imagedata);
}
}
function resizeMe(img) {
var canvas = document.createElement('canvas');
var max_width = 600;
var max_height = 600;
var width = img.width;
var height = img.height;
// calculate the width and height, constraining the proportions
if (width > height) {
if (width > max_width) {
height = Math.round(height * max_width / width);
width = max_width;
}
} else {
if (height > max_height) {
width = Math.round(width * max_height / height);
height = max_height;
}
}
//resize the canvas and draw the image data into it
img.width = width;
img.height = height;
canvas.width = width;
canvas.height = height;
canvas.classname += "ui-hidden";
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, width, height);
return canvas.toDataURL();
}
所以应用程序运行并拍摄照片,一切看起来都很好,但上传到本地存储的数据只是一个空白屏幕。它在黑莓 10 模拟器中 100% 工作,但在我的设备上却不行。在设备上它保存一个空字符串。
编辑
好的。所以我将此添加到我的函数中以进行测试,但我仍然卡住了,我不知道该怎么办......
function sharePhoto(request) {
var image = new Image();
image.src = "file://" + request.data;
image.onload = function () {
// Now here I need to read the image file and convert it into base64.
var resized = resizeMe(image); // the resizeMe function is given below and it simply makes my image smaller
var imagedata = resized.split("base64,");
alert(imagedata); // This returns a blank popup
sessionStorage.setItem("MyNewPicture", imagedata);
}
}
【问题讨论】:
标签: blackberry-10 blackberry-webworks