gpt4 book ai didi

java - 为什么 BitmapFactory.decodeFile 返回 null?

转载 作者:行者123 更新时间:2023-11-29 06:16:45 25 4
gpt4 key购买 nike

我正在试验 android FaceDetector。我需要使用位图文件(faces.bmp 来自合影),因为我还没有找到在 android 模拟器中使用 android 相机的方法。但是 BitmapFactory.decodeFile 返回 null 并且文档只说如果无法解码位图它会返回 null 。它只是一个 24 位 .bmp 文件。我在 Windows 7 上使用 Eclipse。我是否错误地指定了 pathName?我是否需要使用 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);

关于java - 为什么 BitmapFactory.decodeFile 返回 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4820836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com