ImageView从SdCard中获取图片

来源:互联网 发布:我的世界服务器辅助js 编辑:程序博客网 时间:2024/06/05 02:45

private  ImageView c_img;

c_img=(ImageView)findViewById(R.id.img);


1.保存图片

String filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + getTime() + ".jpg";

//phoneFile为图片文件,其中,例如:phonePath="/storage/sdcard0/2015年02月28日 12:52:50.jpg"
phoneFile = new File(filePath);

2.读取图片

String path = phoneFile.getAbsolutePath();
String imgPath = path.substring(path.lastIndexOf("/"),path.length());

//这个地方的地址跟获取的绝对路径的地址不一样
String myJpgPath = "/sdcard/"+imgPath; 
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
Bitmap bm = BitmapFactory.decodeFile(myJpgPath, options);
c_img.setImageBitmap(bm);



0 0
原创粉丝点击