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();
}