酷站(www.ku0.com)-致力于为互联网从业者提供动力!

热门关键词:  企业  as  baidu  c4rp3nt3r  美女
酷站

java

旗下栏目: php js asp Flex Ajax jquery JSP asp.net C语言 java 正则表达式 微信小程序

Java实现图片倒影的源码教程

来源:互联网搜集 作者:秩名 人气: 发布时间:2019-09-03
本篇文章主要介绍了Java实现图片倒影的源码教程,对大家的学习或者工作具有一定的参考学习价值,感兴趣的小伙伴们可以参考一下,也感谢大家对酷站(ku0.com)的支持。
把做工程过程常用的一些代码段做个记录,下面代码是关于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; 
} 
}

原文链接:https://www.cnblogs.com/anemone/p/11452918.html

最新更新