而是做如下图所示 -
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