Domanda

Sto sperimentando con il FaceDetector Android. Ho bisogno di usare un file bitmap (faces.bmp è da una foto di gruppo), poiché non ho trovato un modo per utilizzare la fotocamera Android nell'emulatore Android. Ma i rendimenti BitmapFactory.decodeFile nullo e la documentazione dice solo che restituisce null se la bitmap non può essere decodificato. E 'solo un file bmp 24 bit. Sto usando Eclipse su Windows 7. Ho specificare pathName in modo errato? Ho bisogno di usare qualcosa di diverso da un file a 24 bit .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);
  }
    }
}
È stato utile?

Soluzione

If you are just testing then in place of Bitmap bitmap = BitmapFactory.decodeFile(pathName); you could use:

Bitmap bitmap = BitmapFactory.decodeResource(R.drawable.faces);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top