/**
* 图片绘制3d效果
* @param srcImage
* @param radius
* @param border
* @param padding
* @return
* @throws IOException
*/
public static BufferedImage draw3D(BufferedImage srcImage, int radius, int border, int padding, Color bgColor) throws IOException{
int width = srcImage.getWidth();
int height = srcImage.getHeight();
int size = (width + height ) / 2;
Shape shape = new RoundRectangle2D.Float(0, 0, width, height, radius, radius); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = image.createGraphics(); //绘制渐变背景
if(bgColor == null){
bgColor = Color.LIGHT_GRAY;
}
GradientPaint paint = new GradientPaint(0, 0, bgColor.darker(), 0, height, bgColor.brighter().brighter());
g2d.setPaint(paint);
g2d.setComposite(AlphaComposite.DstIn);
g2d.fillRect(0, 0, width, height); //绘图
g2d.setComposite(AlphaComposite.Src);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.fill(shape);
g2d.setComposite(AlphaComposite.SrcAtop);
g2d.drawImage(setClip(srcImage, radius), 0, 0, null); //设置高亮效果
g2d.setColor(new Color(255, 255, 255, 150));
Shape highlightArea = createHighlightShape(0, 0, size, shape);
g2d.fill(highlightArea); //绘制边框
if(border !=0){
g2d.setColor(Color.LIGHT_GRAY);
g2d.setStroke(new BasicStroke(border));
g2d.drawRoundRect(border / 2, border/2, width- border, height- border, radius, radius);
}
g2d.dispose(); //加旁白
if(padding > 0){
int canvasWidth = width + padding * 2;
int canvasHeight = height + padding * 2;
BufferedImage newImage = new BufferedImage(canvasWidth, canvasHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D gd = newImage.createGraphics();
float[] fractions = {0.0f, 0.6f};
Color[] colors = {Color.LIGHT_GRAY, Color.WHITE};
Point2D center = new Point2D.Float(canvasWidth / 2, canvasHeight /2);
RadialGradientPaint paint2 = new RadialGradientPaint(center, size, fractions, colors);
gd.setPaint(paint2);
gd.setComposite(AlphaComposite.Src);
gd.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
gd.fill(new RoundRectangle2D.Float(0, 0, canvasWidth, canvasHeight, radius, radius));
gd.setComposite(AlphaComposite.SrcAtop);
gd.drawImage(image, padding, padding, null);
return newImage;
}
return image;
} /**
* 图片设置圆角
* @param srcImage
* @return
* @throws IOException
*/
public static BufferedImage draw3D(BufferedImage srcImage) throws IOException{
int radius = (srcImage.getWidth() + srcImage.getHeight()) / 6;
return draw3D(srcImage, radius, 2, 5, null);
} /**
* 图片切圆角
* @param srcImage
* @param radius
* @return
*/
public static BufferedImage setClip(BufferedImage srcImage, int radius){
int width = srcImage.getWidth();
int height = srcImage.getHeight();
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = image.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setClip(new RoundRectangle2D.Double(0, 0, width, height, radius, radius));
g2d.drawImage(srcImage, 0, 0, null);
g2d.dispose();
return image;
} /**
* 描边
*/
public static BufferedImage setBorder(BufferedImage srcImage){
int width = srcImage.getWidth();
int height = srcImage.getHeight();
int border = 1; int nWidth = width + border * 2;
int nHeight = height + border * 2; BufferedImage image = new BufferedImage(nWidth, nHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = image.createGraphics();
int colorIncrement = 4;
for(int i = border; i > 0; i--){
int nw = width + 2 * i;
int nh = height + 2 * i;
BufferedImage tImage = new BufferedImage(nw, nh, BufferedImage.TYPE_INT_ARGB);
Graphics2D tgs = tImage.createGraphics();
tgs.drawImage(srcImage, 0, 0, nw, nh, null); int red = 255 - colorIncrement * (border - i);
int green = 255 - colorIncrement * (border - i);
int blue = 255 - colorIncrement * (border - i);
int rgb = new Color(red, green, blue).getRGB();
System.out.println(rgb);
for(int x = 0 ; x < nw; x++){
for(int y = 0; y < nh; y++){
if(tImage.getRGB(x, y)!=0){
tImage.setRGB(x, y, rgb);
}
}
} tgs.dispose();
g2d.drawImage(tImage, border - i, border -i, null);
}
g2d.drawImage(srcImage, border, border, null);
g2d.dispose();
return image;
} /**
* 高亮层
* @param centerX
* @param centerY
* @param size
* @param body
* @return
*/
private static Shape createHighlightShape(int centerX, int centerY, int size, Shape body) {
double myRadius = size * 4;
double x = centerX - size * 2.3;
double y = centerY - size * 3.2;
Ellipse2D.Double circle = new Ellipse2D.Double(x, y, myRadius, myRadius);
Area area = new Area(circle);
area.intersect(new Area(body));
return area;
}

最新文章

  1. Node.js Stream-基础篇
  2. 在iMac机os x上装win7双系统经验心得
  3. java数据结构
  4. 【OpenStack】OpenStack系列14之Dashboard定制开发
  5. 那些年我们没能bypass的xss filter
  6. eclipse快捷键使用
  7. oracle的基本信息查询
  8. jsonp Ajax跨域请求
  9. iscroll-lite.js源码注释
  10. Android zip文件压缩解压缩
  11. Java绘制艺术图形
  12. 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest I Lottery
  13. Schema与数据类型优化
  14. SpringMVC源码之Controller查找原理
  15. PHP 安装与配置(WIN10)
  16. [Algorithm] 如何正确撸&lt;算法导论&gt;CLRS
  17. base64encode 编码原理
  18. 如何优雅的控制goroutine的数量
  19. SeaJS 与 RequireJS 的差异对比
  20. xtrabackup拷贝redolog前做的细节操作

热门文章

  1. 六种方式实现hibernate查询
  2. Java集合类笔试题
  3. 初探react
  4. php 操作xml文件
  5. Js自动截取字符串长度,添加省略号“……”
  6. htmlspecialchars()函数
  7. HBase笔记--自定义filter
  8. APKTool用法
  9. ural 1837 Isenbaev&#39;s Number
  10. MYSQL正式环境主从复制(不锁表,不停服务)