Question

this problem has been bothering me for days and I cannot figure out why on earth it is happening. I have a method that detects for a face, if a face is detected, the method will draw a rectangle on a canvas along the face.

That part works fine.

The problem is, when it displays to the image_view in my xml file, it will display on the far left middle of the image view, in a box, rather than in the center with the width as fill_parent.

I thought of a possible workaround : to set the bitmap as a bitmapdrawable, but canvas only draws to bitmaps, so I can get the bitmapdrawable in the middle, but with no red box around it.

I commented out my testing of bitmap drawable, and left it as what I have now...it only displays to my xml in the far left of the image_view. Please take a look and help!

I posted to pastebin because the code is a bit long (I am also using a linear layout within a view flipper).

method:

http://pastebin.com/KQ5Pmx45

xml:

http://pastebin.com/jbt3j40h

Since I am able to get the faces to detect, and I can paste a bitmap drawable to an imagebutton and it centers just fine, is there a way to get the rectangle around the bitmapdrawable if my problem cannot be solved?

Thanks!

EDIT: I tried to implement it into a RelativeLayout and still doing the same thing:

http://pastebin.com/daqMdXjB

Could this code be getting my way of centering?

    public void processCameraImage(Intent intent) {
        mFlipper.setDisplayedChild(1); // 1 == your second layout
        mThePicture = (ImageView) findViewById(R.id.image_view); //
        cameraBitmap = (Bitmap) intent.getExtras().get("data");

        mThePicture.setImageBitmap(cameraBitmap);
        detectFaces();

    }
Was it helpful?

Solution

Use on Imageview tag android:scaleType="fitCenter" or android:scaleType="centerInside" or android:scaleType="center" sclaetype attr doc

I hope, I understood your problem right.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top