1
我正在嘗試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);
}
}
}
@jacknad對不起的人,這如何回答你的問題的標題?你不知道decodefile如何返回null ..這不是一起跳過嗎? – baash05 2012-02-13 11:12:32