Reputation: 2211
I have two images in drawable folder and I am doing this:
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);
There is WHITE background in my picture named "image" but i want to show only the object of that picture means want to make the background transparent. How can I do this ?
Upvotes: 0
Views: 1762
Reputation: 560
If your image has white background then you can use setAlpha() for drawable. But the best way is that you should use image with no background.
Example :
imageview.getDrawable().setAlpha(60);
Upvotes: 0
Reputation: 804
You can create a transparent drawable
and make it as the background of the View
.
Android uses Hex ARGB values, which are formatted as #AARRGGBB. That first pair of letters, the AA, represent the Alpha Channel. To set alpha value you must convert your decimal opacity values to a Hexdecimal value.
Here's hex Opacity Values
Upvotes: 0
Reputation: 1332
<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);
Upvotes: 0
Reputation: 18725
You can always use the Transparent color as a background, which is set the same as any drawable, just use @android:color/transparent
Upvotes: 1
Reputation: 8142
You can make the canvas transparent before drawing the images.
canvas.drawColor(Color.TRANSPARENT);
Upvotes: 1