私のアプリでは、顔の位置にあるライブカメラフィードの上に長方形を描きたいだけです..次のコードを使用しています
@Override
public void surfaceCreated(SurfaceHolder holder) {
camera = Camera.open();
try {
camera.setPreviewDisplay(holder);
camera.setPreviewCallback(new PreviewCallback() {
public void onPreviewFrame(byte[]_data, Camera _camera) {
// TODO Do something with the preview image.
byte data[]=_data;
Bitmap b = BitmapFactory.decodeByteArray(data, 0, data.length);
DrawOnTop mDraw.bitmap=b;
addContentView(mDraw, new LayoutParams
(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
//detecteye(bitmap);
}
});
} catch (IOException e)
{ e.printStackTrace();
}
camera.startPreview();
}
class DrawOnTop extends View {
Bitmap bitmap;
public DrawOnTop(Context context,AttributeSet attrs) {
// TODO Auto-generated constructor stub
super(context,attrs);
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
Paint ditherPaint = new Paint();
Paint drawPaint = new Paint();
if(null != bitmap)
{ int width = bitmap.getWidth();
int height = bitmap.getHeight();
FaceDetector detector = new FaceDetector(width, height,1);
Face[] faces = new Face[1];
//Bitmap bitmap565 = Bitmap.createBitmap(width, height, Config.RGB_565);
ditherPaint.setDither(true);
drawPaint.setColor(Color.RED);
drawPaint.setStyle(Paint.Style.STROKE);
drawPaint.setStrokeWidth(2);
//canvas.setBitmap(bitmap565);
//canvas.drawBitmap(bitmap, 0, 0, ditherPaint);
int facesFound = detector.findFaces(bitmap, faces);
PointF midPoint = new PointF();
float eyeDistance = 0.0f;
// float confidence = 0.0f;
// Log.i("FaceDetector", "Number of faces found: " + facesFound);
if(facesFound > 0)
{
for(int index=0; index<facesFound; ++index)
{ // Get the eye distance, detected eye mid point and confidence
faces[index].getMidPoint(midPoint);
eyeDistance = faces[index].eyesDistance();
//confidence = faces[index].confidence();
//Log.i("FaceDetector",
// "Confidence: " + confidence +
//", Eye distance: " + eyeDistance +
//", Mid Point: (" + midPoint.x + ", " + midPoint.y + ")");
// Draw a small rectangle frame around the eye
canvas.drawRect((int)midPoint.x - eyeDistance ,
(int)midPoint.y - eyeDistance ,
(int)midPoint.x + eyeDistance,
(int)midPoint.y + eyeDistance, drawPaint);
}
}
}
super.onDraw(canvas);
} }
しかし、実行時にエラー No command output: 'am start -n in my error log and the app force closes everytime.このエラーを取り除き、私がやりたいことを考えると、それに似た簡単な例があります