框架中的遮罩(裁剪)图像 [英] Masking(crop) image in frame

查看:41
本文介绍了框架中的遮罩(裁剪)图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个丰富的 UI 应用程序,我想在其中显示像这样具有复杂形状的图像

现在我想要的是根据蒙版图像裁剪我的图像,实际上图像是动态的,可以从相机或图库(正方形或矩形形状)导入,我希望该图像适合在我上面的布局框架中

所以只是想知道我是如何做到这一点的?任何想法/提示欢迎

背景框架

面具

喜欢

Having a rich UI application in which I want to show image with complex shape like this

Now what I want is to crop my image as per Mask image, Actually image is coming dynamic and can be imported from Camera or Gallery(square or rectangle shape) and I want that image to fit in my layout frame like above

So just wondering that how do I have achieve this? Any idea /hint welcome

Background frame

Mask

Like this

解决方案

Finally got the solution while changing mask image and using of Xfermode with Bitmap

Mask

 ImageView mImageView= (ImageView)findViewById(R.id.imageview_id);
 Bitmap original = BitmapFactory.decodeResource(getResources(),R.drawable.content_image);
 Bitmap mask = BitmapFactory.decodeResource(getResources(),R.drawable.mask);
 Bitmap result = Bitmap.createBitmap(mask.getWidth(), mask.getHeight(), Config.ARGB_8888);
 Canvas mCanvas = new Canvas(result);
 Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
 paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
 mCanvas.drawBitmap(original, 0, 0, null);
 mCanvas.drawBitmap(mask, 0, 0, paint);
 paint.setXfermode(null);
 mImageView.setImageBitmap(result);
 mImageView.setScaleType(ScaleType.CENTER);
 mImageView.setBackgroundResource(R.drawable.background_frame);

see output

Source can be found here

这篇关于框架中的遮罩(裁剪)图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆