1

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.

Community
  • 1
  • 1
Rafael
  • 3,042
  • 3
  • 20
  • 36
  • 1
    possible duplicate of [Masking(crop) image in frame](http://stackoverflow.com/questions/12614542/maskingcrop-image-in-frame) – tachyonflux Jun 30 '15 at 20:48

1 Answers1

1

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);
tachyonflux
  • 20,103
  • 7
  • 48
  • 67