0

I have a mat object, which has image information used by openCV library for image processing. The mat object is basically a matrix. I need to scale this object to the size of the linear layout in which i need to display after converting it to Bitmap.

The steps would briefly be as follows:- 1. Get the height and width of the linear layout. 2. Scale the mat object to the width and height. 3. Convert the object to bitmap 4. Display the bitmap onto the linear layout

I do all this in the onStart method where the layout with and height is 0. I am failing in the first step.

How do i get the width and height. Also Can i get the coordinates of the linear layout in onstart() method.

Kindly help

Crazy idea would be to display a dummy image first, get the layout width and height and then display the actual image....i am a beginner...

user2768984
  • 57
  • 1
  • 11

1 Answers1

0

Rather do it the other way,as shown below -

i> Convert the Mat image to BitMap. Here is the code for doing so -

Mat mat;
// Intialize mat
Bitmap bitMap = Bitmap.createBitmap(mat.cols(), mat.rows(),Bitmap.Config.ARGB_8888);
Utils.matToBitmap(mat, bitMap);

ii> In the layout file, use an ImageView in the LineatLayout and set the layout_width and fill_height to match_parent. This will use the whole linear layout. Here is the code for doing so -

<ImageView 
    android:id="@+id/image_view"
    android:contentDescription="@string/description"
    android:layout_width= "match_parent"
    android:layout_height="match_parent" />

Don't forget to add description in strings.xml.

iii> Put the Bitmap image in the LinearLayout, as shown below -

ImageView imageView = (ImageView) findViewById(R.id.image_view);
        imageView.setImageBitmap(bitMap);

Using this code, you will be able to display a Mat image in a LinearLayout.

bikz05
  • 1,575
  • 12
  • 17