2014-12-27 18 views
0

透明我在繪製文件夾兩個圖像,我這樣做:如何讓背景中的Android

image = BitmapFactory.decodeResource(getResources(), R.drawable.image1); 
background = BitmapFactory.decodeResource(getResources(), R.drawable.image2); 


canvas.drawBitmap(background,0, 0, null); 
canvas.drawBitmap(image, x, y, null); 

有一個在我的圖片命名爲「圖像」白色背景,但我想說明的只是對象該圖片意味着要使背景透明。 我該怎麼做?

+0

你怎麼樣畫繪製的圖像本身有一個透明的背景是什麼? – Niko 2014-12-27 13:34:11

+0

是的,終於與透明背景一起工作。 – Exigente05 2014-12-30 06:15:48

回答

1

您可以在繪製圖像之前使畫布變透明。

canvas.drawColor(Color.TRANSPARENT); 
1

您可以隨時使用的透明色作爲背景,這是設置與任何可繪製的,只是用@android:color/transparent

0
<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/myimage" 
    android:alpha=".75"/> 
Programatically, you can also set it with 

int alphaAmount = 125; // some value 0-255 where 0 is fully transparent and 255 is fully opaque 
myImage.setAlpha(alphaAmount); 
0

您可以創建一個透明drawable並使其爲背景View

Android使用十六進制ARGB值,格式爲#AARRGGBB。第一對字母AA代表Alpha通道。要設置alpha值,您必須將小數點不透明度值轉換爲十六進制值。

下面是十六進制的不透明度值

  • 100% - FF
  • 95% - F2
  • 90% - E6
  • 85% - D9
  • 80% - CC
  • 75% - BF
  • 70% - B3
  • 65% - A6
  • 60% - 99
  • 55% - 8C
  • 50% - 80
  • 45% - 73
  • 40% - 66
  • 35% - 59
  • 30% - 4D
  • 25% - 40
  • 20% - 33
  • 15% - 26
  • 10% - 1A
  • 5% - 0D
  • 0% - 00
0

如果圖像有白色背景,那麼你可以使用setAlpha()進行繪製。 但最好的方法是你應該使用沒有背景的圖像。

例子:

imageview.getDrawable().setAlpha(60);