android 常用图片处理效果总结

    xiaoxiao2025-06-04  28

    一.Xfermode的简单使用

    1.第一次用canvas绘制的为Dst层 第二次为Src

    图片圆角效果:

    private void innitView() { bmp = BitmapFactory.decodeResource(getResources(), R.drawable.test2); out = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(out); //使用canvas进行绘图 所有操作结果将直接作用在out上 paint = new Paint(Paint.ANTI_ALIAS_FLAG); canvas.drawRoundRect(new RectF(0, 0, bmp.getWidth(), bmp.getHeight()),25,25,paint); //绘制一个圆角矩形 paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); //为画笔增加Xfermode效果 canvas.drawBitmap(bmp, 0, 0, paint); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawBitmap(out, 0,0, null); //将带有效果的out图绘制出来 }

    二.镜面与倒影效果

    private void innitView() { bmp = BitmapFactory.decodeResource(getResources(), R.drawable.test); Matrix matrix = new Matrix(); //建立一个矩阵对象 matrix.setScale(1, -1); //将Y轴取反 得到倒影 out = Bitmap.createBitmap(bmp,0,0, bmp.getWidth(), bmp.getHeight(), matrix, true);//复制一张相同的图 paint = new Paint(); paint.setShader(new LinearGradient(0, bmp.getHeight(), 0, bmp.getHeight()*2, 0XDD000000, 0X10000000, Shader.TileMode.CLAMP));//为画笔设置渐变的效果 } @Override protected void onDraw(Canvas canvas) { canvas.drawBitmap(bmp, 0,0, paint); canvas.drawBitmap(out, 0, out.getHeight(), null); canvas.drawRect(0, out.getHeight(), out.getWidth(), out.getHeight()*2, paint); }
    转载请注明原文地址: https://ju.6miu.com/read-1299591.html
    最新回复(0)