图片设置3D效果
/**
* 图片绘制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;
}

图片设置3D效果的更多相关文章
- 拜托,使用Three.js让二维图片具有3D效果超酷的好吗 💥
声明:本文涉及图文和模型素材仅用于个人学习.研究和欣赏,请勿二次修改.非法传播.转载.出版.商用.及进行其他获利行为. 背景 逛 sketchfab 网站的时候我看到有很多二维平面转 3D 的模型例子 ...
- 原生js实现图片的3d效果
<!doctype html><html lang="en"><head><meta charset="UTF-8"& ...
- 3d效果的图片轮播
CSS3的3d变换 CSS3给我们提供了一个新的功能,那就是3d变换.3d变换和2d变换的基本API函数类似,只不过多了些在Z轴上的操作,不难使用. 但是,为了让元素拥有3d变换的功能,我们需要给他的 ...
- wpf 模拟3D效果(和手机浏览图片效果相似)(附源码)
原文 wpf 模拟3D效果(和手机浏览图片效果相似)(附源码) pf的3D是一个很有意思的东西,类似于ps的效果,类似于电影动画的效果,因为动画的效果,(对于3D基础的摄像机,光源,之类不介绍,对于依 ...
- WPF 图片浏览 伪3D效果
原文:WPF 图片浏览 伪3D效果 首先上效果图: 因项目要求,需要把图片以"好看"."炫"的效果展示出来,特地研究了一下WPF关于3D方面的制作,奈何最终成果 ...
- jQuery旋转木马仿3D效果的图片切换特效代码
用jQuery实现的一款仿3D效果的图片切换特效代码,类似旋转木马一样,幻灯图片以三维视觉上下滑动切换,效果很酷炫,兼容IE8.360.FireFox.Chrome.Safari.Opera.傲游.搜 ...
- ios UIButton设置单选效果,以及同时设置图片和标题
一,设置单选效果 - (void)selectedBtnPress:(UIButton*)sender { //首先把原来按钮的选中效果消除 for (int i=0;i<num;i++) {/ ...
- iOS开发中的错误整理,启动图片设置了没有效果;单独创建xib需要注意的事项;图片取消系统渲染的快捷方式
一.启动图片设置了没有效果 解决方案:缓存啊!卸了程序重新安装吧!!!!! 二.单独创建xib需要注意的事项 三.图片取消系统渲染的快捷方式
- WPF技术触屏上的应用系列(四): 3D效果图片播放器(图片立体轮放、图片立体轮播、图片倒影立体滚动)效果实现
原文:WPF技术触屏上的应用系列(四): 3D效果图片播放器(图片立体轮放.图片立体轮播.图片倒影立体滚动)效果实现 去年某客户单位要做个大屏触屏应用,要对档案资源进行展示之用.客户端是Window7 ...
随机推荐
- Dapper基本增删改查
说明: 1.在using语句块中不用dbConnection.Open(),因为Execute方法中会Open,并且在执行完成会Close. 2.在Ado.Net中要手动Open,在Using语句块中 ...
- css与div小结
前些时间学习css与div的课程 什么是css呢 Css 级联样式表或层叠样式表(Cascading Style Sheet) 是能够真正做到 网页表现与内容分离的一种样式设计语言.相对于传统HTML ...
- span里设置高度
众所周知,SPAN元素内单纯设置height是没有效果的. 需要设置SPAN的高度,需要将其设置成block元素. display:block 但这样会导致span占据了整一行,我们通常不希望这样. ...
- linux笔记2.19
压缩一般使用 tar -cvzf etcbackup.tar.gz /etc 寻找文件 locate(快速查找:新添加的得用updatedb更新后才能找到) find: find . -name ...
- dede仿站笔记
仿站步骤查看是否为dedecms的方法,看引用路径src="/templets/default2012/images/toutiao.png" 0查看仿站编码,选择utf8或gbk ...
- Poweroff – 很好很强大的定制关机工具
Poweroff – 很好很强大的定制关机工具 Poweroff 是一个用来管理电脑关机系统的小工具,支持定时,支持远程 作者开放源代码,有兴趣的同学可以尝试着制作一下汉化版本. 可以设定不同时间 ...
- string标准库的使用
string s; s.empty() 如果 s 为空串,则返回 true,否则返回 false. s.size() 返回 s 中字符的个数 s[n] 返回 s 中位置为 n 的字符,位置从 开始计数 ...
- Java基础学习第二天
================每日必读==================== 写代码: 1.明确需求.我需要实现什么需求? 2.分析思路.我需要怎么实现需求? 3.确定步骤.我的每一部分思路需要使 ...
- python实现发工资脚本
好开心啊,在旁边大神的帮助下,终于实现了发工资的python脚本,之前用shell写的老出错,刚才测试,发80个人工资详情,妥妥的,代码如下: from email.mime.multipart im ...
- UIApplication-备用
iPhone应用程序是由主函数main启动,它负责调用UIApplicationMain函数,该函数的形式如下所示: int UIApplicationMain ( int argc, char *a ...