Java实现图片倒影的源码实例内容
程序员文章站
2023-11-18 18:12:28
把做工程过程常用的一些代码段做个记录,下面代码是关于java实现图片倒影的的代码,应该对大家有较大用处。
public class but...
把做工程过程常用的一些代码段做个记录,下面代码是关于java实现图片倒影的的代码,应该对大家有较大用处。
public class buttonimageactivity extends activity { private imageview image_btn; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); image_btn=(imageview)findviewbyid(r.id.image_btn); bitmap bitmap =((bitmapdrawable)getresources().getdrawable(r.drawable.image_btn)).getbitmap(); image_btn.setimagebitmap(createreflectedimage(bitmap)); image_btn.setonclicklistener(new onclicklistener() { public void onclick(view v) { } }); } private bitmap createreflectedimage(bitmap originalbitmap) { final int reflectiongap = 4; int width = originalbitmap.getwidth(); int height = originalbitmap.getheight(); matrix matrix = new matrix(); matrix.prescale(1, -1); bitmap reflectionbitmap = bitmap.createbitmap(originalbitmap, 0, height / 2, width, height / 2, matrix, false); bitmap withreflectionbitmap = bitmap.createbitmap(width, (height + height / 2 + reflectiongap), config.argb_8888); canvas canvas = new canvas(withreflectionbitmap); canvas.drawbitmap(originalbitmap, 0, 0, null); paint defaultpaint = new paint(); canvas.drawrect(0, height, width, height + reflectiongap, defaultpaint); canvas.drawbitmap(reflectionbitmap, 0, height + reflectiongap, null); paint paint = new paint(); lineargradient shader = new lineargradient(0, originalbitmap.getheight(), 0, withreflectionbitmap.getheight(), 0x70ffffff, 0x00ffffff, tilemode.mirror); paint.setshader(shader); paint.setxfermode(new porterduffxfermode(mode.dst_in)); canvas.drawrect(0, height, width, withreflectionbitmap.getheight(), paint); return withreflectionbitmap; } }
以上就是本次介绍的全部知识点内容,感谢大家对的支持。