Android(安卓)图片的加载与保存
16lz
2021-01-24
从手机中加载图片
- Filefile=newFile("/data/data/capture.bmp");
- if(file.exists()){//判断文件是否存在
- bm=BitmapFactory.decodeFile("/data/data/capture.bmp");//通过BitmapFactory将图片文件转成Bitmap
- //iv.setImageBitmap(bm);//使用ImageView的setImageBitmap()显示图片
- }else{
- //文件不存在
- newAlertDialog.Builder(Image.this).setIcon(R.drawable.icon)
- .setTitle("文件不存在").setPositiveButton("ok",newDialogInterface.OnClickListener(){
- publicvoidonClick(DialogInterfacedialog,intwhich){}
- }).show();
- }
- Filef=newFile("/data/data/1.png");
- f.createNewFile();
- FileOutputStreamfOut=null;
- try{
- fOut=newFileOutputStream(f);
- }catch(FileNotFoundExceptione){
- e.printStackTrace();
- }
- bmp1.compress(Bitmap.CompressFormat.PNG,100,fOut);
- try{
- fOut.flush();
- }catch(IOExceptione){
- e.printStackTrace();
- }
- try{
- fOut.close();
- }catch(IOExceptione){
- e.printStackTrace();
- }
更多相关文章
- Android学习之路四:ImageView
- button imageButton 背景透明
- Android(安卓)Shader应用开发之雷达扫描效果
- Android核心基础-3.Android(安卓)开发环境搭建
- Android调用手机拍照以及从相册选择照片
- Android(安卓)基本原理&移动终端软件开发课程&StudyAccount8 201
- android的图片加载和伸缩处理
- 如何调用android内置图片,比如menu->add的加号图片,search的放大镜
- Android(安卓)网络通信框架Volley简介