我是安卓新手。我正在尝试实现照片标记应用程序,我们可以在其中标记面部,如 facebook 照片标记。我能够找到面孔并在面孔上绘制矩形。
EditText
但是当用户触摸这些矩形时,我试图在面部识别的矩形上放置一个(写名字)。一旦完成,我需要禁用EditText
并需要显示TextView
(名称)。请在下面找到代码并帮助我。
代码:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
layout = new LinearLayout(this);
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
myEditTet = new EditText(this);
myView custom = new myView(this);
layout.addView(myEditTet);
myEditTet.setVisibility(View.GONE);
// layout.addView(myTextView);
// myTextView.setVisibility(View.GONE);
layout.addView(custom, params); // Of course, this too
setContentView(layout);
}
private class myView extends View {
private int imageWidth, imageHeight;
private int numberOfFace = 5;
private FaceDetector myFaceDetect;
private FaceDetector.Face[] myFace;
float myEyesDistance;
int numberOfFaceDetected;
Bitmap myBitmap;
public myView(Context context) {
super(context);
// TODO Auto-generated constructor stub
BitmapFactory.Options BitmapFactoryOptionsbfo = new BitmapFactory.Options();
BitmapFactoryOptionsbfo.inPreferredConfig = Bitmap.Config.RGB_565;
myBitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.face3, BitmapFactoryOptionsbfo);
imageWidth = myBitmap.getWidth();
imageHeight = myBitmap.getHeight();
myFace = new FaceDetector.Face[numberOfFace];
myFaceDetect = new FaceDetector(imageWidth, imageHeight,
numberOfFace);
numberOfFaceDetected = myFaceDetect.findFaces(myBitmap, myFace);
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
canvas.drawBitmap(myBitmap, 0, 0, null);
Paint myPaint = new Paint();
myPaint.setColor(Color.GREEN);
myPaint.setStyle(Paint.Style.STROKE);
myPaint.setStrokeWidth(3);
for (int i = 0; i < numberOfFaceDetected; i++) {
android.media.FaceDetector.Face face = myFace[i];
PointF myMidPoint = new PointF();
face.getMidPoint(myMidPoint);
myEyesDistance = face.eyesDistance();
dx = (int) (myMidPoint.x - myEyesDistance);
dy = (int) (myMidPoint.y - myEyesDistance);
dz = (int) (myMidPoint.x + myEyesDistance);
dt = (int) (myMidPoint.y + myEyesDistance);
canvas.drawRect((int) (myMidPoint.x - myEyesDistance),
(int) (myMidPoint.y - myEyesDistance),
(int) (myMidPoint.x + myEyesDistance),
(int) (myMidPoint.y + myEyesDistance), myPaint);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
myEditTet.setVisibility(View.VISIBLE);
if (event.getX() > dx && event.getX() < dz && event.getY() > dy
&& event.getY() < dt) {
Log.i("SARDAR", "RECT TOUCH 1111");
}
return super.onTouchEvent(event);
}
}
}