189 8069 5689

Java中怎么实现一个图片倒影效果-创新互联

Java中怎么实现一个图片倒影效果,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

创新互联主营福贡网站建设的网络公司,主营网站建设方案,app软件开发公司,福贡h5小程序开发搭建,福贡网站营销推广欢迎福贡等地区企业咨询

public class ButtonImageActivity extends Activity {private ImageView image_btn;@Overridepublic 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; } }

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注创新互联行业资讯频道,感谢您对创新互联网站建设公司,的支持。


新闻标题:Java中怎么实现一个图片倒影效果-创新互联
分享地址:http://cdxtjz.cn/article/phdce.html

其他资讯