为什么BitmapFactory.decodeFile返回null?
问题描述:
我正在尝试android FaceDetector。 我需要使用位图文件(faces.bmp来自组照片),因为我还没有找到在android模拟器中使用android相机的方法。 但BitmapFactory.decodeFile返回null,并且文档只说它在位图无法解码时返回null。它只是一个24位.bmp文件。我在Windows 7上使用Eclipse。我没有正确指定pathName?我需要使用除24位.bmp文件以外的内容吗?为什么BitmapFactory.decodeFile返回null?
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);
@jacknad对不起的人,这如何回答你的问题的标题?你不知道decodefile如何返回null ..这不是一起跳过吗? – baash05 2012-02-13 11:12:32