在Android的本地保存图片 [英] Save Image locally in Android

查看:173
本文介绍了在Android的本地保存图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android的新的。我想存储我的形象(这是从画廊或粘性图片选择从摄像机)在本地(即共享preferences)。我要救我的图片,直到应用程序将在设备上运行。一旦应用程序将从设备中删除,那么所有的数据将被删除。

I am new in Android. I want to store my image(which is chosen from gallery or tack picture from Camera) locally(i.e. SharedPreferences). I want to save my images till application will run in device. Once application will be removed from device then all data will be removed.

谁能帮我?

感谢。

推荐答案

调用这个函数保存。

void saveImage() {

File myDir=new File("/sdcard/saved_images");
    myDir.mkdirs();

    String fname = "Image.jpg";
    File file = new File (myDir, fname);
    if (file.exists ()) file.delete (); 
    try {
           FileOutputStream out = new FileOutputStream(file);
           finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
           out.flush();
           out.close();
           final AlertDialog alertDialog = new AlertDialog.Builder(this).create();  
                alertDialog.setTitle("Save");  
                alertDialog.setMessage("Your drawing had been saved:)");  
                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {  
                public void onClick(DialogInterface dialog, int which) { 
                    return;  
                }  
            });  
            alertDialog.show();
    } catch (Exception e) {
           e.printStackTrace();
    }
}

这篇关于在Android的本地保存图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆