我正试图用下一个代码用凸轮制作一张照片,但我总是犯同样的错误:
skia(446): --- SkImageDecoder::Factory returned null
(它没有抛出异常)。因此,对象位图始终为NULL,我无法看到pic只是用凸轮制作的,我可以用Eclipse的文件资源管理器看到它。
发生什么事了?我怎样才能解决这个问题?
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.view_photo);
ImageView imagen = (ImageView)findViewById(R.id.foto);
try {
Cursor cur = this.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, null, null, null,null);
String str = cur.getString(cur.getColumnIndex(MediaStore.Images.ImageColumns.DISPLAY_NAME));
cur.moveToLast();
FileInputStream in = new FileInputStream("/sdcard/DCIM/Camera/" + str);
BufferedInputStream buf = new BufferedInputStream(in, 24);
Bitmap bMap = BitmapFactory.decodeStream(buf);
if (bMap != null)
imagen.setImageBitmap(bMap);
else{
Log.d("onCreate: ", "bMap es NULL");
}
if (in != null) {
in.close();
Log.d("onCreate: ", "in cerrado");
}
if (buf != null) {
buf.close();
Log.d("onCreate: ", "buf cerrado");
}
Log.d("onCreate: ", "Fin del proceso");
}catch (Exception e) {
Log.e("Error reading file", e.toString());
}
}
答案 0 :(得分:0)
尝试以下方法:
// get the SD Card path, you need to check first if this is available
File sdcard = Environment.getExternalStorageDirectory();
// I am assuming str is your filename, make sure you are getting the right value for this one
File file = new File(sdcard.getAbsolutePath(), str);
// Note that the buffer size is in bytes, so 24 in your question is very low
BufferedInputStream buf = new BufferedInputStream(in, 8192);
Bitmap bMap = BitmapFactory.decodeStream(buf);