【发布时间】:2017-09-08 06:42:18
【问题描述】:
我正在制作一个允许用户拍照的 android 应用程序,然后该应用程序将打印一些 RGB 值等。我正在保存手机上拍摄的照片,然后从这些 png 文件中制作位图。我刚刚发现我应该让应用程序休眠一会儿才能保存图像。但是对于我拍摄的某些图像,我仍然认为位图为空。如果我用 6 种不同颜色拍摄魔方的图像,我几乎永远不会得到空指针异常。但是,如果我拍摄墙壁或其他东西的照片,则位图 = null。
有谁知道我应该怎么做才能解决这个问题?
Bitmap myBitmap;
final String dir =
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) +
"/picFolder/";
try{
file = dir+Integer.toString(side)+".jpg";
File f = new File(file);
options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
myBitmap = BitmapFactory.decodeFile(file,options);
for(int i = 0; i<3; i++){
for(int j = 0; j<3; j++){
cube[side-1][i][j] = getColor(myBitmap, i, j);
}
}
}catch (Exception e){
Log.e("er0r", "HERE:::: " + e.toString());
}
【问题讨论】:
-
请贴一些代码。 “我正在保存手机拍摄的照片”是什么意思?你在控制相机吗?有一个意图返回图像。
-
我现在添加了代码。该应用程序打开相机并允许用户拍照并将其保存在手机上。然后应用程序尝试从照片中制作位图,但有时它为空。
-
您遇到错误了吗?你怎么知道 myBitmap 为空?
-
更改,
Log.e("er0r", "HERE:::: " + e.toString());到Log.e("er0r", "HERE:::: " + e.toString(), e);然后重新创建问题并将 logcat 中的堆栈跟踪添加到您的问题中 -
好吧,在文档中
inJustDecodeBounds - If set to true, the decoder will return null (no bitmap), but the out...
标签: java android image bitmap null