2011-09-05 62 views
0

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

任何人都可以帮助我吗?

谢谢。

+0

您应该添加更多的细节......你谈论一个摄取的图像,然后像计划** S ** ......顺便说一句,看看Android服务。 ..如果你希望你的应用程序保存图像,即使它没有启动。 – Whiler

回答

0

调用这个函数用于保存..

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