Android 使用面检测将xy位置设置为图像视图

Android 使用面检测将xy位置设置为图像视图,android,android-layout,position,imageview,Android,Android Layout,Position,Imageview,我在我的应用程序中检测到一张脸。我使用两个ImageView,第一个用于面部,第二个用于遮罩。我需要在计算的面部位置上设置遮罩位置,然后可以使用触摸事件移动遮罩。对于触摸事件,我使用了本教程: 遮罩缩放的方法可以返回面位置。我尝试将XY位置设置为遮罩图像视图,但始终显示在位置0.0处。在脸上。然后我可以将遮罩图像视图移到脸上。“视图”是我的面具。理想情况下,我需要在面部位置上初始化遮罩imageview 对不起,我的英语不好 protected Bitmap draw(int mode) {

我在我的应用程序中检测到一张脸。我使用两个ImageView,第一个用于面部,第二个用于遮罩。我需要在计算的面部位置上设置遮罩位置,然后可以使用触摸事件移动遮罩。对于触摸事件,我使用了本教程:

遮罩缩放的方法可以返回面位置。我尝试将XY位置设置为遮罩图像视图,但始终显示在位置0.0处。在脸上。然后我可以将遮罩图像视图移到脸上。“视图”是我的面具。理想情况下,我需要在面部位置上初始化遮罩imageview

对不起,我的英语不好

protected Bitmap draw(int mode) {

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.c10);

    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    Point position = new Point();

    xRatio = anchoCara * 1.0f / anchoCara;
    yRatio = altoCara * 1.0f / altoCara;


    Bitmap resizedBitmap = null;

    float factor = 9.6f;//9.6

    for (int i = 0; i < eyesMidPts.length; i++) {
        if (eyesMidPts[i] != null) {
            pOuterBullsEye.setStrokeWidth(eyesDistance[i] / 6);

            float newWidth = eyesDistance[i] * factor;
            float newHeight = eyesDistance[i] * factor;

            float scaleWidth = (newWidth) / width;
            float scaleHeight = (newHeight) / height;

            Matrix matrix = new Matrix();
            matrix.postScale(scaleWidth, scaleHeight);

            resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width,
                    height, matrix, true);

            position.set(
                            (int) ((eyesMidPts[i].x * xRatio) - (eyesDistance[i] * factor) ),//2
                            (int) ((eyesMidPts[i].y * yRatio) - (eyesDistance[i] * factor) ));

            Log.e("Face", "positio x : " + position.x);
            Log.e("Face", "positio y : " + position.y);


            Log.e("Face", "mascara width : " + resizedBitmap.getWidth());
            Log.e("Face", "mascara heigth : " + resizedBitmap.getHeight());
//              view.setBackgroundDrawable(new BitmapDrawable(resizedBitmap));
//              view.setAdjustViewBounds(true);
//              Log.i("Face", "positio x : " + view.getScrollX());
//              Log.i("Face", "positio y : " + view.getScrollY());
        }
    }
    return resizedBitmap;
}
受保护位图绘制(int模式){
位图Bitmap=BitmapFactory.decodeResource(getResources(),R.drawable.c10);
int width=bitmap.getWidth();
int height=bitmap.getHeight();
点位置=新点();
xRatio=anchoCara*1.0f/anchoCara;
yRatio=altoCara*1.0f/altoCara;
位图resizedBitmap=null;
浮动系数=9.6f;//9.6
对于(int i=0;i
最后,我使用了下一个代码:

@Override
public void onGlobalLayout() {
    // TODO Auto-generated method stub
    faceDetect(MODO_VIEW);      
    Display m=getWindowManager().getDefaultDisplay();
    anchoPant=m.getWidth();
    Log.i("Face","separacion derecha: "+((anchoPant-cara.getWidth())/2)+"px" );
    MyAbsoluteLayout.LayoutParams mp=new MyAbsoluteLayout.LayoutParams(MyAbsoluteLayout.LayoutParams.WRAP_CONTENT, MyAbsoluteLayout.LayoutParams.WRAP_CONTENT, (anchoPant-cara.getWidth())/2, 0);
    cara.setLayoutParams(mp);

    //view.setBackgroundDrawable(new BitmapDrawable(draw(MODO_VIEW)));      
    view.setImageBitmap(draw(MODO_VIEW));       
    MyAbsoluteLayout.LayoutParams lp=new MyAbsoluteLayout.LayoutParams(MyAbsoluteLayout.LayoutParams.WRAP_CONTENT,MyAbsoluteLayout.LayoutParams.WRAP_CONTENT,position.x+((anchoPant-cara.getWidth())/2),position.y);
    view.setLayoutParams(lp);
    view.getViewTreeObserver().removeGlobalOnLayoutListener(this);

}

在我的问题中,该方法可以返回位置,然后使用MyAbsoluteLayout.LayoutParams over OnGlobalLayout()设置XY位置不会出现问题。

我读得太快,认为问题标题为“性感位置”。完全失望。