繁体   English   中英

如何在图像视图中不带代码的情况下显示相机最后捕获的图​​像

[英]How to show the last captured image from the camera without code in Image view

我是Titanium Android Mobile应用程序开发的新手。

我的问题是如何在图像视图中加载相机的最后捕获图像。

我在一个窗口中有一个被称为“点击”的Bitton,并且必须在第二个窗口中显示该图像。

我将如何实现这一目标,所以仅使用Titanium android不需要代码。

谢谢

试试这个代码...

Ti.Media.showCamera({
    success : function(event) {

       if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
          // Here you can do whatever you want with the image captured from the camera
          var imgView = Ti.UI.CreateImageView({
             image: event.media,
             width: Ti.UI.SIZE, height: Ti.UI.SIZE
          });
          Ti.UI.currentWindow.add(imgView); // It will be added to the centre of the window if you didn't specify top or left or ...
       } else {
        alert("got the wrong type back =" + event.mediaType);
       }        
    },
    cancel : function() {
       alert("You have cancelled !");
    },
    error : function(error) {
       alert("error");
    },
       saveToPhotoGallery : true,
       allowEditing : true,
       mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO]
});

您将通过Callback接口的方法接收捕获的图像数据。 回调接口用于提供照片捕获的图像数据。

Camera.PictureCallback

onPictureTaken(byte[] data, Camera camera)
{
     ......
     Your code
     ......
}

您可以在此处对图像数据做任何想做的事情。 意味着您可以在此处将图像设置为imageview。 您将以字节为单位接收数据。 只需将其转换为drawable / bitmap并将该drawable / bitmap设置为imageview即可。 而已!

要将字节转换为位图,可以使用以下链接: 如何将字节数组转换为位图

感谢您的所有回复...我自己解决了这个问题。

var image = event.media;

然后使用nativePath捕获图像的本机路径

image.nativePath

然后将此路径存储到应用程序属性,并使用Application getString函数重用此属性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM