2011-11-27 4 views
0

Je suis nouveau sur Android et la programmation. J'utilise l'api Android touchpaint, et en utilisant le code suivant pour enregistrer un dessin, mais évidemment l'enregistrement est inutile sans pouvoir ouvrir le fichier. Je me demandais si quelqu'un pouvait m'aider avec un code pour cela.comment ouvrir un fichier sur 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; 
    } 
} 

Répondre

0
Bitmap bitmap = BitmapFactory.decodeFile(pathToFile); 

Voir la documentation pour plus d'informations.