android 画人脸识别圆圈
package com.android.ovaldemo;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
public class Oval extends View {
private Paint mPaint;
private Bitmap mWhiteDot;
private Bitmap mBitmapCheck;
private Bitmap mFinishGlow;
private static final float POINTS [][] ={
{ 0.0F,-1.0F},
{ 0.16F, -0.98F},
{ 0.34F, -0.92F},
{ 0.5F, -0.82F},
{ 0.64F, -0.7F},
{ 0.74F, -0.54F},
{ 0.78F, -0.36F},
{ 0.8F, -0.18F},
{ 0.78F, 0.0F},
{ 0.75F, 0.2F},
{ 0.7F, 0.37F},
{ 0.62F, 0.54F},
{ 0.52F, 0.71F},
{ 0.4F, 0.83F},
{ 0.26F, 0.94F},
{ 0.08F, 1.0F},
{ -0.08F, 1.0F},
{ -0.26F, 0.94F},
{ -0.4F, 0.83F},
{ -0.52F, 0.71F},
{ -0.62F, 0.54F},
{ -0.7F, 0.37F},
{ -0.75F, 0.2F},
{ -0.78F, 0.0F},
{ -0.8F, -0.18F},
{ -0.78F, -0.36F},
{ -0.74F, -0.54F},
{ -0.64F, -0.7F},
{ -0.5F, -0.82F},
{ -0.34F, -0.92F},
{ -0.16F, -0.98F}
};
public Oval(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
mPaint = new Paint();
mWhiteDot = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_facial_dot);
mBitmapCheck = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_facial_dot_check);
mFinishGlow = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_facial_dot_correct);
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
int i = 0;
float f2,f3,f4,f5,f6,f7;
while (i < POINTS.length) {
f2 = 0.37F * (POINTS[i][0] * (float)getWidth()) + (float)(getWidth() / 2);
f3 = 0.37F * (POINTS[i][1] * (float)getWidth()) + (float)(getHeight() / 2);
f4 = f2 - (float)(mFinishGlow.getWidth() / 2);
f5 = f3 - (float)(mFinishGlow.getHeight() / 2);
f6 = f2 - (float)(mWhiteDot.getWidth() / 2);
f7 = f3 - (float)(mWhiteDot.getHeight() / 2);
canvas.drawBitmap(mWhiteDot, f6, f7, mPaint);
i++;
}
}
}
效果图:


浙公网安备 33010602011771号