2012-06-28 69 views
0

我想捕捉使用相机的图像并将其放入android屏幕。我正在使用sencha touch 2,phonegap用于相机功能。它正在捕获图像但不显示在屏幕上。 这里是我的代码:使用相机拍摄图像后,照片不返回到我的屏幕

在dashboardpanel文件:

{ 
     xtype : 'image', 
     id : 'capturedimage', 
     src : '', 
     width : 60, 
     height: 60, 
     width : 200 
}, 
{ 
     xtype : 'container', 
     id : 'btncontainer', 
     width : 120, 
     layout : { 
        type : 'vbox' 
       }, 
     items : [ 
     { 
       xtype : 'button', 
       height : 73, 
       cls : 'capturebtn', 
       id : 'capturebtn', 
       width : 100 
     }, 
     { 
       xtype : 'button', 
       height : 73, 
       margin : '10 0 0 0', 
       cls : 'choosephotobtn', 
       id : 'selectphoto', 
       width : 100 
      } ] 
    }, 

在Controller文件::

onCaptureButtonTap: function(button, e, options) { 
    /** 
    * phonegap Camera 
    */ 

    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true }); 

     function onFail(message) { 
      alert('Failed because: ' + message); 
     } 

     function onPhotoDataSuccess(imageData) { 
      // Uncomment to view the base64 encoded image data 
      console.log(imageData); 

      // Get image handle 
      // 
      var smallImage = document.getElementById('capturedimage'); 

      // Unhide image elements 
      // 
      smallImage.style.display = 'block'; 

      // Show the captured photo 
      // The inline CSS rules are used to resize the image 
      // 
      smallImage.src = imageData; 
     } 

    } 

但它不来了。请问任何人可以帮我...

+0

你看到'adb logcat'输出中的任何错误? – dhaval

+0

不,它没有给出任何logcat错误。 –

+0

你检查了@Simon的最后一条评论以打印成功的输出 – dhaval

回答

0

最后我能够解决这个使用下面的链接:

Solution Link

1

这是因为我们现在默认使用getPicture的FILE_URI返回类型。所以现在你只需获取文件的url,而不用关闭所有的base64编码数据。这是一个更好的方法,因为它没有使用太多的内存。改变这一行:

image = "data:image/jpeg;base64," + imageData; 

到:

image.src = imageData; 

,你应该准备就绪。

+0

谢谢西蒙。我试过了,但没有工作。 –

+0

在面板中,我认为图像部分是创建问题。我不是getiing .. –

+0

我不是Sencha专家,所以要确保PG片正常工作在onPhotoDataSuccess方法中做一个console.log(imageData),以便我们可以确保它正在调用正确。 –

1

花花公子!尝试设置图像HTML IMG SRC =“” ID =“”东西你会得到在屏幕上的形象

+0

如何做到这一点..我编辑了代码。当我在控制台中打印它时,它会给我base64编码的图像数据。像这样:07-23 12:25:55.015:I/Web控制台(7215):content:// media/external/images/media/125 at:899934341 –

相关问题