1

我正在尝试使用 android FaceDetector。我需要使用位图文件(faces.bmp 来自合影),因为我还没有找到在 android 模拟器中使用 android 相机的方法。但是 BitmapFactory.decodeFile 返回 null 并且文档只说如果无法解码位图则返回 null。它只是一个 24 位的 .bmp 文件。我在 Windows 7 上使用 Eclipse。我是否错误地指定了路径名?我是否需要使用 24 位 .bmp 文件以外的其他文件?

public class MyFaces extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final int width = 600;
        final int height = 600;
        final int maxFaces = 8;
        FaceDetector faceDetector = new FaceDetector(width, height, maxFaces);
        String pathName = "../res/drawable-hdpi/faces.bmp";
        try {
         Bitmap bitmap = BitmapFactory.decodeFile(pathName);
         Face faces[] = new Face[maxFaces];
            int nFaces = faceDetector.findFaces(bitmap, faces);
            Log.d(this.getClass().toString(), "Faces: " + nFaces);
  } catch (Exception e) {
   Log.e(this.getClass().toString(), e.getMessage(), e);
  }
    }
}
4

1 回答 1

3

如果您只是在测试,Bitmap bitmap = BitmapFactory.decodeFile(pathName);那么可以使用:

Bitmap bitmap = BitmapFactory.decodeResource(R.drawable.faces);
于 2011-01-27T19:40:04.650 回答