首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >黑莓网站10使用图片拍摄的图片\上传

黑莓网站10使用图片拍摄的图片\上传
EN

Stack Overflow用户
提问于 2013-11-25 16:14:50
回答 2查看 224关注 0票数 0

我被一个问题困住了,我不知道下一步该做什么。

在我的应用程序中,我为我的用户提供了一个选择,要么拍摄一张照片,要么从画廊中选择一张照片。这部分工作正常,问题的产生与保存\阅读照片。让我们从摄像机调用的角度看这个问题。

代码语言:javascript
复制
function startCameraApp() {
    PhotoTaken = false;
    blackberry.event.addEventListener("onChildCardClosed", sharePhoto);

    blackberry.invoke.invoke({
        target: "sys.camera.card"
    }, onInvokeSuccess, onInvokeError);
}

在sharePhoto中我有以下代码..。

代码语言:javascript
复制
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();
}

因此,这个应用程序运行,它拍摄了照片,一切看起来都很好,但上传到本地存储的数据只是一个空白屏幕。它100%的工作在黑莓10模拟器,但不是在我的设备上。在设备上,它保存了一个空字符串。

编辑

好的。所以我把这个添加到我的函数中,用于测试,我仍然被困住了,我不知道该怎么做……

代码语言:javascript
复制
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);
    }
}
EN

回答 2

Stack Overflow用户

发布于 2013-11-26 18:46:00

我相信当您使用split方法时,它会返回一个数组,所以您可以这样访问它:

代码语言:javascript
复制
var resized = resizeMe(image);
var imagedata = resized.split("base64,");
    imagedata = imagedata[1]; // this gives you everything after the 'base64,' string

但是,我看到的主要问题是,您正在拆分imagedata字符串,该字符串从数据中删除了整个“这是一个图像”前缀。

当您将imagedata显示为图像时,您需要有数据: image /jpeg;base64 64,前缀。

所以说,你的图像来源是

代码语言:javascript
复制
data:image/jpeg;base64,<rest of base64 string here>
票数 1
EN

Stack Overflow用户

发布于 2013-11-27 05:18:55

我需要在我的应用程序的config.xml中包含一个额外的元素。

代码语言:javascript
复制
<access subdomains="true" uri="file://accounts/"></access>
<access subdomains="true" uri="file://accounts/100/shared/camera/"></access>

这使您的应用程序可以访问这些文件夹及其包含的文件。模拟器的不需要这个权限。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20197794

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档