而是做如下圖所示 -
i>將Mat
圖片轉換爲BitMap
。這裏是這樣做的代碼 -
Mat mat;
// Intialize mat
Bitmap bitMap = Bitmap.createBitmap(mat.cols(), mat.rows(),Bitmap.Config.ARGB_8888);
Utils.matToBitmap(mat, bitMap);
II>在佈局文件中,使用在一個LineatLayout
ImageView
並設置layout_width
和fill_height
到match_parent
。這將使用整個線性佈局。這裏是這樣做的代碼 -
<ImageView
android:id="@+id/image_view"
android:contentDescription="@string/description"
android:layout_width= "match_parent"
android:layout_height="match_parent" />
不要忘了在strings.xml
添加description
。
III>放入LinearLayout
的Bitmap
圖像,如下所示 -
ImageView imageView = (ImageView) findViewById(R.id.image_view);
imageView.setImageBitmap(bitMap);
使用該代碼,則能夠在一個LinearLayout
以顯示圖像Mat
。
scaletype fitxy爲imageview ..你試試吧。 – Dhina 2014-10-12 05:40:41
我沒有圖像視圖。我有一個對象,Mat對象。我需要將對象縮放到佈局的寬度和高度。 – user2768984 2014-10-12 06:59:15
Mat對象用於openCV。用於圖像處理 – user2768984 2014-10-12 07:00:52