質問

Android FaceDeTectorを実験しています。 AndroidエミュレータでAndroidカメラを使用する方法を見つけていないため、BitMapファイル(FACES.BMPはグループ写真からのものです)を使用する必要があります。ただし、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);
  }
    }
}
役に立ちましたか?

解決

あなたがただテストしている場合、その代わりに Bitmap bitmap = BitmapFactory.decodeFile(pathName); 使用できます:

Bitmap bitmap = BitmapFactory.decodeResource(R.drawable.faces);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top