android 图片存sd卡上,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();
}
原文:http://www.cnblogs.com/mlj318/p/4512355.html
總結
以上是生活随笔為你收集整理的android 图片存sd卡上,android打开,保存图片到sd卡,显示图片的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: BZOJ 4241 分块
- 下一篇: 电脑系统重装篇6:使用微PE工具箱制作U