给图片倒圆角
来源:互联网 发布:入骨相思知不知小说 编辑:程序博客网 时间:2024/05/18 09:15
public class mhFillet {
public static final int LEFT = 1;
public static final int RIGHT = 2;
public static final int TOP = 3;
public static final int BOTTOM = 4;
public static final int ALL = 5;
// public enum HalfType {
// LEFT, // 左上角 + 左下角
// RIGHT, // 右上角 + 右下角
// TOP, // 左上角 + 右上角
// BOTTOM, // 左下角 + 右下角
// ALL // 四角
// }
//
/**
* 将图片的四角圆弧化
*
* @param bitmap 原图
* @param roundPixels 弧度
* @param half (上/下/左/右)半部分圆角
* @return
*/
public static Bitmap getRoundCornerImage(Bitmap bitmap, int roundPixels, int half) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Bitmap roundConcerImage = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);//创建一个和原始图片一样大小的位图
Canvas canvas = new Canvas(roundConcerImage);//创建位图画布
Paint paint = new Paint();//创建画笔
Rect rect = new Rect(0, 0, width, height);//创建一个和原始图片一样大小的矩形
RectF rectF = new RectF(rect);
paint.setAntiAlias(true);// 抗锯齿
canvas.drawRoundRect(rectF, roundPixels, roundPixels, paint);//画一个基于前面创建的矩形大小的圆角矩形
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));//设置相交模式
case LEFT:
return Bitmap.createBitmap(roundConcerImage, 0, 0, width - roundPixels, height);
case RIGHT:
return Bitmap.createBitmap(roundConcerImage, width - roundPixels, 0, width - roundPixels, height);
case TOP: // 上半部分圆角化 “- roundPixels”实际上为了保证底部没有圆角,采用截掉一部分的方式,就是截掉和弧度一样大小的长度
return Bitmap.createBitmap(roundConcerImage, 0, 0, width, height - roundPixels);
case BOTTOM:
return Bitmap.createBitmap(roundConcerImage, 0, height - roundPixels, width, height - roundPixels);
case ALL:
return roundConcerImage;
default:
return roundConcerImage;
}
}
}
public static final int LEFT = 1;
public static final int RIGHT = 2;
public static final int TOP = 3;
public static final int BOTTOM = 4;
public static final int ALL = 5;
// public enum HalfType {
// LEFT, // 左上角 + 左下角
// RIGHT, // 右上角 + 右下角
// TOP, // 左上角 + 右上角
// BOTTOM, // 左下角 + 右下角
// ALL // 四角
// }
//
/**
* 将图片的四角圆弧化
*
* @param bitmap 原图
* @param roundPixels 弧度
* @param half (上/下/左/右)半部分圆角
* @return
*/
public static Bitmap getRoundCornerImage(Bitmap bitmap, int roundPixels, int half) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Bitmap roundConcerImage = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);//创建一个和原始图片一样大小的位图
Canvas canvas = new Canvas(roundConcerImage);//创建位图画布
Paint paint = new Paint();//创建画笔
Rect rect = new Rect(0, 0, width, height);//创建一个和原始图片一样大小的矩形
RectF rectF = new RectF(rect);
paint.setAntiAlias(true);// 抗锯齿
canvas.drawRoundRect(rectF, roundPixels, roundPixels, paint);//画一个基于前面创建的矩形大小的圆角矩形
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));//设置相交模式
canvas.drawBitmap(bitmap, null, rect, paint);//把图片画到矩形去
switch (half) {
return Bitmap.createBitmap(roundConcerImage, 0, 0, width - roundPixels, height);
case RIGHT:
return Bitmap.createBitmap(roundConcerImage, width - roundPixels, 0, width - roundPixels, height);
case TOP: // 上半部分圆角化 “- roundPixels”实际上为了保证底部没有圆角,采用截掉一部分的方式,就是截掉和弧度一样大小的长度
return Bitmap.createBitmap(roundConcerImage, 0, 0, width, height - roundPixels);
case BOTTOM:
return Bitmap.createBitmap(roundConcerImage, 0, height - roundPixels, width, height - roundPixels);
case ALL:
return roundConcerImage;
default:
return roundConcerImage;
}
}
}
0 0
- 给图片倒圆角
- 给图片倒圆角
- 给图片添加图片水印
- 给图片添加水印图片
- 给图片加上水印
- 给图片加上水印
- 给图片添加水印
- /给图片打水印
- 给图片添加水印
- js给图片加圆角
- 给图片加水印
- 给图片加标记
- 给图片添加水印
- 给图片添加阴影
- 给图片添加水印
- 给图片加水印
- 给图片加水印
- 给图片加水印
- html5 audio标签切换播放音乐的方法
- 第六章 CSS
- android 的四大组件之Broadcast Receiver
- Android的.so文件、ABI和CPU的关系
- latex与word之间的各种转化方法
- 给图片倒圆角
- BOM浏览器对象模型(brower object model)
- 关于移植过程中,存在大量LCD log(不定形参...)等调试属性函数宏定义到printf
- 设计模式(5)工厂模式-后记
- http协议 简介
- 面向对象(六)
- spring基本用法总结
- 关于 Warning:The `android.dexOptions.incremental` property is deprecated and it has no effect on the b
- SVN服务器搭建和eclipse插件安装和.net插件安装