2015-01-17 115 views
0

我有一個未來的看法:保存照片拼貼

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="350dp" 
    android:layout_height="350dp" 
    android:orientation="horizontal"> 

    <LinearLayout 
     android:layout_width="140dp" 
     android:layout_height="match_parent" 
     android:layout_marginRight="2.5dp" 
     android:orientation="vertical"> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginBottom="2.5dp" 
      android:layout_weight="1" 
      android:longClickable="true" 
      android:scaleType="matrix" 
      android:src="@drawable/a1" /> 


     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginTop="2.5dp" 
      android:layout_weight="1" 
      android:longClickable="true" 
      android:scaleType="matrix" 
      android:src="@drawable/a2" /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@android:color/transparent"> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_gravity="center" 
      android:layout_marginLeft="2.5dp" 
      android:longClickable="true" 
      android:scaleType="matrix" 
      android:src="@drawable/a4" /> 
    </LinearLayout> 
</LinearLayout> 

它看起來像:enter image description here

在此視圖中,用戶可以編輯這個圖片的觀看(縮放,旋轉)

我必須保存編輯過的照片拼貼。如何使用放大和縮小的照片保存視圖?是否有可能將編輯的視圖保存在位圖中以應用程序緩存?

感謝您的幫助!

+0

我在列表中有三個位圖。如何以編程方式將它們拼貼成圖像。 –

回答

4

是的,你可以簡單地把編輯的圖像的截圖並創建可以在任何地方你想

下面保存的位圖是用於獲取位圖

public Bitmap getBitMap() { 
    try { 
     yourEditedPhotoCollageLayout.buildDrawingCache(); 
     Bitmap bmp = Bitmap.createBitmap(yourEditedPhotoCollageLayout.getDrawingCache()); 
     return bmp; 
    } catch (Exception e) { 
     e.printStackTrace(); 
     return null; 
    } 
} 

而這樣一來,你可以保存功能bitmap

private void saveBitmap(Bitmap bitmap) { 
    try { 
     File storageDir = createImageFile(); 
     String path = storageDir.toString(); 
     OutputStream out = new FileOutputStream(path); 
     bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); 
     out.close(); 

     MyMediaConnectorClient client = new MyMediaConnectorClient(path); 
     MediaScannerConnection scanner = new MediaScannerConnection(
       Context, client); 
     client.setScanner(scanner); 
     scanner.connect(); 

    } catch (IOException e) { 
     Log.e("save image", "failed to save image", e); 
    } 
} 
+0

非常感謝你! –

+0

歡迎你的朋友:) –