Why does BitmapFactory.decodeFile return null?
I am experimenting with the android FaceDetector. I need to use a bitmap file (faces.bmp is from a group photo) since I have not found a way to use the android camera in the android emulator. But BitmapFactory.decodeFile returns null and the documentation only says it returns null if the bitmap could not be decoded. It is just a 24 bit .bmp file. I am using Eclipse on Windows 7. Did I specify pathName incorrectly? Do I need to use something other than a 24 bit .bmp file?
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.ge开发者_开发知识库tClass().toString(), e.getMessage(), e);
}
}
}
If you are just testing then in place of Bitmap bitmap = BitmapFactory.decodeFile(pathName);
you could use:
Bitmap bitmap = BitmapFactory.decodeResource(R.drawable.faces);
精彩评论