0
Here I was using 3 Image_Views inside the Frame_Layout,I just want to save My Frame LayOut With Loaded Image Views to Gallery/SD card 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/frame1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@color/bg_dim_gray" 
    > 

    <FrameLayout android:id="@+id/frame" 
     android:background="@color/White" 
     android:layout_marginTop="30dp" 
     android:layout_marginBottom="150dp" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="fill_parent" android:layout_height="fill_parent" 
      android:layout_marginTop="2.0dip" 
      android:layout_marginBottom="2.0dip" 
      android:layout_marginLeft="2.0dip" 
      android:layout_marginRight="2.0dip" > 



    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 

     android:layout_weight="1.0" 
     android:orientation="vertical" > 
     <FrameLayout android:layout_height="0.0dip" android:layout_width="fill_parent" 
       android:background="@color/BurlyWood" android:layout_weight="0.3"> 
     <ImageView android:id="@+id/photoImage" android:background="@color/BurlyWood" android:clickable="true" 
         android:layout_width="fill_parent" android:layout_height="fill_parent" 
          /> 
     </FrameLayout> 
     <FrameLayout android:layout_height="0.0dip" android:layout_width="fill_parent" 
       android:background="@color/BurlyWood" android:layout_weight="0.3"> 
     <ImageView android:id="@+id/photoImage1" android:background="@color/BurlyWood" android:clickable="true" 
         android:layout_width="fill_parent" android:layout_height="fill_parent" /> 
     </FrameLayout> 
     <FrameLayout android:layout_height="0.0dip" android:layout_width="fill_parent" 
       android:background="@color/BurlyWood" android:layout_weight="0.3"> 
     <ImageView android:id="@+id/photoImage2" android:background="@color/BurlyWood" android:clickable="true" 
         android:layout_width="fill_parent" android:layout_height="fill_parent" /> 
     </FrameLayout> 
     </LinearLayout> 
     </LinearLayout> 



     <ImageView 
      android:id="@+id/frame1" 
      android:background="@drawable/ic_border3" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      /> 



    </FrameLayout> 

    <LinearLayout android:gravity="center" android:layout_width="0.0dip" android:layout_height="40.0dip" android:layout_weight="1.0"> 
         <Button android:textColor="@color/white" 
          android:layout_width="fill_parent" android:layout_height="fill_parent" 
          android:text="Save" /> 
    </RelativeLayout> 

這是我在Java文件中使用的代碼,想要在Frame/SD卡上保存FrameLayout它包含圖像視圖?

btn_save.setOnClickListener(新OnClickListener(){

 @Override 
     public void onClick(View arg0) { 
      // TODO Auto-generated method stub 
      frm=(FrameLayout)findViewById(R.id.frame); 
      frm.setDrawingCacheEnabled(true); 
      frm.buildDrawingCache(); 
      bitmap = frm.getDrawingCache(); 
      try { 
       File rootFile=new File(Environment.getExternalStorageDirectory()+File.separator+"MYBOARD"+File.separator); 
       rootFile.mkdirs(); 

       FileOutputStream fileOutputStream = new FileOutputStream(rootFile); 
       bitmap.compress(CompressFormat.PNG, 100, fileOutputStream); 
       fileOutputStream.flush(); 
       fileOutputStream.close(); 

      } catch (Exception e) { 
      } 
     } 
    }); 
+0

我作了一些修改和現在弄明白了, – Crishnan

回答

0

我試圖這樣,它現在可以正常使用

try { 
         File rootFile=new File(Environment.getExternalStorageDirectory().toString()+"/MYBOARD"); 
         rootFile.mkdirs(); 
         Random generator = new Random(); 
         int n = 10000; 
         n = generator.nextInt(n); 
         String fname = "Image-"+ n +".png"; 

         resultingfile=new File(rootFile, fname); 

         if (resultingfile.exists()) resultingfile.delete(); 
         try { 
           FileOutputStream Fout = new FileOutputStream(resultingfile); 
           bitmap.compress(CompressFormat.PNG, 100, Fout); 
           Fout.flush(); 
           Fout.close(); 

         } catch (Exception e) { 
           e.printStackTrace(); 
         } 
} catch (Exception e) { 
       } 
1

無法保存瀏覽到SD卡或任何I/O流,因爲它們不是序列化和Parcelable,但是你可以一個ImageView的圖像保存爲

BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable(); 
    Bitmap bitmap = drawable.getBitmap(); 
    try { 
     FileOutputStream fileOutputStream = new FileOutputStream("your path to save file"); 
     bitmap.compress(CompressFormat.PNG, 100, fileOutputStream); 
     fileOutputStream.flush(); 
     fileOutputStream.close(); 
    } catch (Exception e) { 
    } 

,如果你想保存整個畫面佈局的背景,如SD圖像卡上點擊按鈕,下面寫一個Button OnClickListener代碼...

FrameLayout frameLayout = (FrameLayout)findViewById(R.id.frame); 
    frameLayout.setDrawingCacheEnabled(true); 
    frameLayout.buildDrawingCache(); 
    Bitmap bitmap = frameLayout.getDrawingCache(); 
    try { 
     FileOutputStream fileOutputStream = new FileOutputStream("your path to save file"); 
     bitmap.compress(CompressFormat.PNG, 100, fileOutputStream); 
     fileOutputStream.flush(); 
     fileOutputStream.close(); 
    } catch (Exception e) { 
    } 
+0

我需要檢查這段代碼,你測試過這段代碼了嗎?其實我有多個框架佈局,如果我點擊SaveButton(onclick)框架佈局必須保存到gallery/sd – Crishnan

+0

哪個framelayout要保存?清除... –

+0

我在上面的代碼中使用了FrameLayout android:id =「@ + id/frame」。這個完整的「frame」我想保存在Gallery @Gopal Rao中 – Crishnan