简体   繁体   English

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

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

I am new to the Titanium Android Mobile application development. 我是Titanium Android Mobile应用程序开发的新手。

My problem is how do i load the last captured image of camera in an image view. 我的问题是如何在图像视图中加载相机的最后捕获图像。

I have a bitton called as click in one window and I have to display that image in second window. 我在一个窗口中有一个被称为“点击”的Bitton,并且必须在第二个窗口中显示该图像。

How will I achieve this , remebr no code is needed only using the Titanium android. 我将如何实现这一目标,所以仅使用Titanium android不需要代码。

Thanks 谢谢

Try this code... 试试这个代码...

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]
});

You will receive the captured image data via a method of the Callback interface. 您将通过Callback接口的方法接收捕获的图像数据。 Callback interface is used to supply image data from a photo capture. 回调接口用于提供照片捕获的图像数据。

Camera.PictureCallback

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

You can do whatever you want to do with image data here. 您可以在此处对图像数据做任何想做的事情。 Means you can set the image to imageview here. 意味着您可以在此处将图像设置为imageview。 You will receive data in bytes. 您将以字节为单位接收数据。 Simply convert it to drawable/bitmap and set that drawable/bitmap to the imageview. 只需将其转换为drawable / bitmap并将该drawable / bitmap设置为imageview即可。 Thats it! 而已!

For converting bytes to bitmap you can use this link : How to convert byte array to Bitmap 要将字节转换为位图,可以使用以下链接: 如何将字节数组转换为位图

Thanks for all the response ... I have solved this my own. 感谢您的所有回复...我自己解决了这个问题。

var image = event.media; var image = event.media;

then capture the native path for the image using nativePath 然后使用nativePath捕获图像的本机路径

image.nativePath image.nativePath

and then store this path to the application property and reuse this property using Application getString function. 然后将此路径存储到应用程序属性,并使用Application getString函数重用此属性。

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

相关问题 如何在图像视图的另一个活动中加载从相机捕获的图片? - how to load a picture captured from camera in another activity on image view? 如何通过相机将捕获的图像发送到下一个视图 - how to send captured image by camera to a next view 如何将相机拍摄的图像存储在图库中? - How to store image captured from camera in gallery? 如何获取从CAMERA拍摄的裁剪图像 - How to get croped image captured from CAMERA 如何在 android 中保存从相机拍摄的图像 - How to save captured image from camera in android 如何在相机捕获的图像上叠加图像或视图 - How to overlay an image or view on top of a camera captured image 如何将手机摄像头拍摄的图像从一个活动移动到另一个活动的图像视图? - How to move image captured with the phone camera from one activity to an image view in another activity? 如何获取Android相机捕获的最后一张图像的路径? - How to get the path to the last image captured by Android camera? 获取使用Android相机拍摄的最后一张图像 - Get last image captured using camera on Android 是否可以在不返回到应用程序的情况下裁剪从Android上的Camera捕获的图像? - Is it possible to crop an image captured from the Camera on Android without returning to the app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM