Reputation: 3122
I was tring to make a ImageView that follows a shape of another ImageView's source, or even its own background. I want something like this:
But I'm getting this:
When I try this:
<ImageView android:id="@+id/mimage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:maxHeight="80dp" android:src="@drawable/ic_chat_conteudo_balao" android:background="@mipmap/pomba" android:maxWidth="80dp"/>
Or this:
When I try this:
<ImageView android:id="@+id/mimage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:maxHeight="80dp" android:src="@mipmap/pomba" android:background="@drawable/ic_chat_conteudo_balao" android:maxWidth="80dp"/>
I've also tried following this answer, but it was not what I want:
Well, I don't know what to do anymore. Is there a way to put a bitmap inside another bitmap following its shape?
Here are the images I'm working on
I think this is not a duplicate because I am working with 9-patch, it's a little bit different as karaokyo said.
Upvotes: 1
Views: 734
Reputation: 20211
I guess it is a little bit different if you use a 9-patch mask.
ImageView imageView = (ImageView) findViewById(R.id.mimage);
NinePatchDrawable mask = (NinePatchDrawable) getResources().getDrawable(R.drawable.balloon);
Bitmap original = BitmapFactory.decodeResource(getResources(), R.drawable.pomba);
Bitmap result = Bitmap.createBitmap(original.getWidth(), original.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(result);
canvas.drawBitmap(original, 0, 0, null);
mask.getPaint().setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
mask.setBounds(new Rect(0, 0, original.getWidth(), original.getHeight()));
mask.draw(canvas);
imageView.setImageBitmap(result);
Upvotes: 1