android打开,保存图片到sd卡,显示图片
1.打开根目录下test.jpg
Bitmap bm = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getAbsolutePath()+"/test.jpg");
int[] pixels = new int[bm.getWidth()*bm.getHeight()];
bm.getPixels =(pixels,0,bm.getWidth(),0,0,bm.getWidth(),bm.getHeight() );
Bitmap bm1 = bm.copy(bm.getConfig(),true);//bm is not Mutable ,像素值不能改
bm1.setPixels(pixels,0,bm.getWidth(),0,0,bm.getWidth(),bm.getHeight() );
saveBitmap("test2",bm1);
ImageVie imgview = (ImageView)findViewById(R.id.imageView1);
imgview.setImageBitmap(bm1);
2.保存图片
public void saveBitmap(String name,Bitmap mBitmap){
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+name+".png");
file.createNewFile();
FileOutPutStream fout = null;
fout = new FileOutPutStream(file);
mBitmap.compress(Bitmap.CompressFormat.PNG,100,fout);
fout.flush();
fout.close();
}
更多相关文章
- android 模拟器对应像素
- android 字体大小像素的设置
- android 字体大小,样式 ,像素的设置
- android 获取sd卡根目录
- Android - 像素密度和屏幕适配
- android通过USB的MTP模式下,禁止用户在根目录有任何操作(重命名 删
- Android 自定义像素AVD模拟器无键盘
- Android 中如何得到字符的像素宽度
- android 获取外置sd卡根目录