我正在尝试开发一款可以执行以下操作的游戏:
1。向用户显示gui [一个简单的圆圈]
2。在用户观看显示屏的同时,我想从前置摄像头捕获图像
我在网上找到的大多数示例代码片段都使用旧的Camera API或不起作用。
GameActivity
public class GameActivty extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new com.oculid.ballmoves.GameView(this));
}
}
GameView类
public class GameView extends View implements OnTaskCompleted{
Circle circle;
Paint paint;
String TAG = "GameView";
private MainThread thread;
Client task = new Client(this);
public GameView(Context context) {
super(context);
circle = new Circle(100, 100 ,100);
paint = new Paint();
paint.setColor(Color.RED);
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
}
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
canvas.drawColor(Color.BLUE);
canvas.drawCircle(circle.x, circle.y, circle.r, paint);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
circle.x = event.getX();
circle.y = event.getY();
invalidate();
sendDataToServer();
return true;
}
}
我想创建另一个类(我猜想使用线程),该类在后台从前置摄像头捕获图像(不向用户显示任何预览)