2012-02-20 40 views
0

在這裏我需要保存什麼我dwan的油漆和背景iamge到SD卡。嘗試了一些方法,但在這裏只保存背景image.paints不保存。你有任何人建議我。如何將繪圖保存到android中的sdcard

   public void save() { 
       String filename5; 
          Date date = new Date(0); 
        SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMMddHHmmss"); 
          filename5 = sdf.format(date); 


     try{ 
     mBitmap=BitmapFactory.decodeResource(getResources(),R.drawable.writingsapce); 

      String path = Environment.getExternalStorageDirectory().toString(); 
       OutputStream fOut = null; 
       File file = new File(path, "/DCIM/"+filename5+".jpg"); 
        fOut = new FileOutputStream(file); 

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

      MediaStore.Images.Media.insertImage(getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName()); 
     } catch (Exception e) { 
      e.printStackTrace(); 
      }} 
+0

我覺得這裏你是不是節省您繪製的新形象,但只是原來的一個。把你的繪圖方法,所以我們可以告訴你如何繼續;-) – youssoua 2012-02-20 14:00:18

回答

0

試試這個片段,我用它和它的工作;-)

try { 
       FileOutputStream out = new FileOutputStream(filename); 
       mBitmap.compress(Bitmap.CompressFormat.PNG, 90, out); 
     } catch (Exception e) { 
       e.printStackTrace(); 
     } 

      String path = Environment.getExternalStorageDirectory().toString(); 
      OutputStream fOut = null; 
      File file1 = new File(path, "FitnessGirl"+Contador+".jpg"); 
      fOut = new FileOutputStream(file1); 

      mBitmap.compress(Bitmap.CompressFormat.PNG, 85, fOut); 
      fOut.flush(); 
      fOut.close(); 

      MediaStore.Images.Media.insertImage(getContentResolver(),file1.getAbsolutePath(),file1.getName(),file1.getName()); 
+0

海這裏康塔多意味着什麼? – user1083266 2012-02-20 13:10:17

+0

contador只是一個字符串值,隨機一個,這樣我就可以在同一個文件夾中保存很多圖像,而不必處理異常 – youssoua 2012-02-20 13:45:02

+0

而且對於保存原始文件或繪製文件的內容,請仔細閱讀。給我一點時間來重寫我的代碼,我會發布給你 – youssoua 2012-02-20 13:46:44

相關問題