A newbie question
I have this layers.xml that I use as a source for an ImageView. And two images, mask.png and image.jpg
layers.xml:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:src="@drawable/image" android:gravity="center"/>
</item>
<item>
<bitmap android:src="@drawable/mask" android:gravity="center"/>
</item>
</layer-list>
ImageView:
<ImageView
android:id="@+id/img_B"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/layers"/>
At the moment the output is just the png over the image.
I would like the png to act as a mask, clipping the image using the png alpha channel like so:
Is that possible directly within the xml, or do I have to do it by code?
Thanks for your advice ;)
update: at the moment I achieved my goal using code to replace the entire ImageView
ImageView img = (ImageView) findViewById(imgID);
Canvas canvas = new Canvas();
Bitmap mainImage = BitmapFactory.decodeResource(getResources(), R.drawable.img);
Bitmap mask = BitmapFactory.decodeResource(getResources(), R.drawable.mask);
Bitmap result = Bitmap.createBitmap(mainImage.getWidth(), mainImage.getHeight(), Bitmap.Config.ARGB_8888);
canvas.setBitmap(result);
Paint paint = new Paint();
paint.setFilterBitmap(false);
canvas.drawBitmap(mainImage, 0, 0, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
canvas.drawBitmap(mask, 0, 0, paint);
paint.setXfermode(null);
img.setImageBitmap(result);
img.invalidate();