在帧屏蔽(裁剪)图像 [英] Masking(crop) image in frame

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

问题描述

有中,我想展示图像形状复杂的像这样

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

像<一个href="http://stackoverflow.com/questions/5299452/how-can-i-crop-an-image-with-mask-and-combine-it-with-another-image-background">this

推荐答案

终于得到了解决,而不断变化的掩模图像,并使用 Xfermode 位图

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

面膜

 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);

见输出

来源可以发现的 这里

Source can be found here

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

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