2012-04-11 115 views
0

你好,我想創建一個圓形的圖像女巫有一個小的邊框,並加載用戶個人資料圖片,就像谷歌加Android應用程序一樣。 的問題是,我需要設置圖像作爲按鈕的繪製頂部,所以我發現這個代碼:android創建谷歌加喜歡個人資料圖片

public BitmapDrawable putOverlay(Bitmap bitmap, Bitmap overlay) { 
    Canvas canvas = new Canvas(bitmap); 
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG); 
    canvas.drawBitmap(overlay, 0, 0, paint); 
    return new BitmapDrawable(bitmap); 
} 

女巫應該在另一個位圖疊加一個位圖(用戶PIC)(橢圓形但想到的是a)圓形位圖覆蓋用戶的個人資料圖片,b)用戶的個人資料圖片太大。 任何建議如何做到這一點,或者如果我至少在正確的方式是非常感謝。

UPDATE

我已成功使用此代碼,以顯示兩個圖像:

public BitmapDrawable putOverlay(Bitmap bitmap, Bitmap overlay) { 
    int width = overlay.getWidth()-50; 
    int height = overlay.getHeight()-50; 

    Bitmap b = Bitmap.createScaledBitmap(bitmap, width, height,true); 
    Canvas canvas = new Canvas(overlay); 
    canvas.save(); 
    canvas.translate(width,height); 
    Matrix matrix = new Matrix(); 
    canvas.drawBitmap(overlay, matrix, null); 
    canvas.restore(); 
    canvas.drawBitmap(b,matrix, null); 
    BitmapDrawable completeImage = new BitmapDrawable(getResources(),overlay); 
    return completeImage; 
} 

的問題是,如個人資料圖片繪製資料圖片未對齊到circulare image.Its從相同的x,y位置繪製circulare圖像。 也請注意,資料圖片加載使用:

bitmap = BitmapFactory.decodeStream((InputStream) new URL(imagepath).getContent()); 
+0

你有沒有想過這個? – 2014-04-19 19:07:02

回答

1

使用此代碼(第一縮放輪廓PIC然後應用覆蓋)

public BitmapDrawable putOverlay(Bitmap bitmap, Bitmap overlay) { 
    Bitmap b = Bitmap.createScaledBitmap(bitmap, overlay.getWidth(), overlay.getHeight(),true); 
    Canvas canvas = new Canvas(b); 
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG); 
    canvas.drawBitmap(overlay, 0, 0, paint); 
    return new BitmapDrawable(b); 
} 

我不太讓你在什麼意思問題是覆蓋層位於配置文件頂部pic

+0

沒有這沒有做的伎倆,我的意思是,我想創建一個像谷歌加Android應用程序的圖像必須顯示在主儀表板的用戶配置文件。要做到這一點,我讀了一個簡單的白色圓圈圖像,然後嘗試覆蓋用戶配置文件中的實際圖像。從白色圓圈中顯示輪廓圖像的情況正好相反。 – maxsap 2012-04-12 22:55:33

+0

你可以傳遞一個白色正方形的疊加圖像,並在中心切出一個圓形,這樣上面的代碼就會產生想要的效果。 – saarraz1 2012-04-13 18:11:25

相關問題