2011-11-27 169 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; 
    } 
} 

回答