菜鸟boss 2015-11-13 02:29 采纳率: 5%
浏览 1380

各位大大帮我看看这段代码哪里有误急啊!!!!!

OutputStream fos=null;
InputStream is = getResources().openRawResource(Shuzu.tupians[poistion]);
Log.e("当前的数组里面的是什么呢", "Shuzu.tupians[poistion]"+Shuzu.tupians[poistion]);
Log.e("656565656565656565656565656565656565656", ""+R.drawable.ldgh1);
if (is!=null) {
Log.e("我当前的流不为空", "获取到了我当前的流"+is);
}else{
Log.e("我当前的流为空", "没有获取到了我当前的流"+is);
}
Bitmap bitmap=BitmapFactory.decodeStream(is);
if (bitmap!=null) {
Log.e("我当前的bitmap不为空", "好开心好开心 我离成功又进了一步");
}else{
Log.e("我当前的bitmap不为空", "哎前面的流肯定没有获取到数据");
}
File lufile=new File(Environment.getExternalStorageDirectory(), "tuce");
if (!lufile.exists()) {
lufile.mkdirs();
}
Log.e("我是否创建了文件夹", ""+lufile.getAbsolutePath());
String fileName = System.currentTimeMillis()+poistion+ ".jpg";
File file = new File(lufile, fileName);
Log.d("33333333333333333333333333333333333333333333333333333333", file.getAbsolutePath());
try {
fos = new FileOutputStream(file);
bitmap.compress(CompressFormat.JPEG, 100, fos);
Log.e("000000000000000000000000000000000000000000000", "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
fos.flush();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}finally{
if (is!=null) {
try {
is.close();
} catch (IOException e) {
Log.e("输入流为空", "图片获取失败");
e.printStackTrace();
}
}
if (fos!=null) {
try {
fos.close();
} catch (IOException e) {
Log.e("输出流为空", "关闭失败");
e.printStackTrace();
}
}
}

    try {
        MediaStore.Images.Media.insertImage(getApplicationContext().getContentResolver(),
                file.getAbsolutePath(), fileName, null);
        Log.e("图册已执行", "66666666666666666666666666666666666666666666666666666666666666");
    } catch (FileNotFoundException e) {
        Log.e("图册执行失败请检查", "444444444444444444444444444444444444444444444444444444444");
        e.printStackTrace();
    }
    getApplicationContext().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://"+Environment.getExternalStorageDirectory())));
    if (bitmap.isRecycled()) {
        bitmap.recycle();
        System.gc();
    }
  • 写回答

2条回答 默认 最新

  • danielinbiti 2015-11-13 02:35
    关注

    先看android日志,报什么错误

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog