2014-06-21 37 views
0

對於我的應用程序,我按照我的要求創建了兩個位圖。合併兩個位圖數據

一個用於經過某些圖像處理的實際圖像,另一個用於僅在左上角顯示應用程序徽標的第二個徽標位圖。

現在保存時間我想結合這些位圖,並希望生成單個JPEG文件作爲輸出。

要完成此任務,我寫下面的代碼。

orignalbitmap = orignalbitmap.copy(Config.ARGB_8888, true); 
Canvas savedCanvas = new Canvas(orignalbitmap); 
savedCanvas.setBitmap(logoBitmap); 
savedCanvas.drawBitmap(orignalbitmap, 0, 0, transPaint); 
savedCanvas.drawBitmap(logoBitmap, 0, 0, transPaint); 


try { 
    orignalbitmap.compress(CompressFormat.JPEG, 100, new FileOutputStream(new File("/mnt/sdcard/original.jpg"))); 
} catch (FileNotFoundException e) { 
    e.printStackTrace(); 
} 

但目前我只有我的原始圖像作爲輸出沒有附加標誌。我想要帶有徽標的圖像,也可以使用徽標位圖中的數據。因此,如何結合我無法理解的兩個位圖數據,請在此提供一些指導。

回答

1

使用該功能用於在單個位圖

public static Bitmap combineImages(Bitmap c, Bitmap s) 
{ 
    Bitmap cs = null; 

    int width, height = 0; 

    if(c.getWidth() > s.getWidth()) { 
     width = c.getWidth() + s.getWidth(); 
     height = c.getHeight(); 
    } else { 
     width = s.getWidth() + s.getWidth(); 
     height = c.getHeight(); 
    } 

    cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 

    Canvas comboImage = new Canvas(cs); 

    comboImage.drawBitmap(c, 0f, 0f, null); 
    comboImage.drawBitmap(s, c.getWidth(), 0f, null); 

    return cs; 
} 
+0

這裏我要重疊兩個圖像例如幀佈局組合兩個位圖。我想現在你明白了我的觀點。 – Siddharth