2011-11-27 168 views
0

我是新来的android和编程。我正在使用android touchpaint api,并使用下面的代码来保存绘图,但显然,保存是无用的,无法打开文件。如何在Android上打开文件

我想知道是否有人可以帮我一些代码。

// Function saves image to file 
public String save(Bitmap mBitmap, boolean showMsg) { 
    String filename; 
    Date date = new Date(); 
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); 
    filename = sdf.format(date); 
    try { 

     String path = Environment.getExternalStorageDirectory().toString() + "/modTouchPaint/"; 
     File file1 = new File(path); 
     file1.mkdirs(); 

     OutputStream fOut = null; 
     File file = new File(path, filename + ".jpg"); 
     fOut = new FileOutputStream(file); 

     mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fOut); 
     fOut.flush(); 
     fOut.close(); 

     if (showMsg) 
      Toast.makeText(this, "Picture saved to " + path + filename + ".jpg", 9000).show(); 

     return path + filename + ".jpg"; 
    } catch (Exception e) { 
     e.printStackTrace(); 

     Toast.makeText(this, "Please make sure that SD card is installed", 5000).show(); 

     return null; 
    } 
} 

回答