【问题标题】:Save Image locally in Android在 Android 中本地保存图像
【发布时间】:2011-09-05 08:40:26
【问题描述】:

我是 Android 新手。我想将我的图像(从图库中选择或从相机中选择)存储在本地(即 SharedPreferences)。我想保存我的图像,直到应用程序在设备中运行。一旦应用程序从设备中删除,所有数据都将被删除。

谁能帮帮我?

谢谢。

【问题讨论】:

  • 你应该添加更多细节......你谈到一个挑选的图像,然后是图像s......顺便说一句,看看android服务......如果你想要的话即使未启动,您的应用程序也会保存图像。

标签: android


【解决方案1】:

调用此函数进行保存..

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();
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-02
    • 2016-09-01
    • 1970-01-01
    • 2021-01-29
    • 1970-01-01
    • 2021-05-29
    • 1970-01-01
    • 2017-03-03
    相关资源
    最近更新 更多