我堅持一個問題,我不知道接下來要嘗試什麼。黑莓webworks 10使用圖片拍攝上傳
在我的應用程序中,我爲用戶提供了選擇拍照或從照片庫中選擇照片的選項。這部分工作正常,問題出現在照片的保存\讀取。讓我們從相機調用的角度來看這個。
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);
}
}
split確實返回一個數組。這不是我得到我的問題的原因。我使用base64,l作爲分隔符,以便我可以輕鬆地檢索base64字符串。你可以在下面看到我的答案,是什麼導致了我的問題。謝謝您的回覆。 – KapteinMarshall