簡體   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