代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Java
】
以图片填充边框
作者:
DDT
/ 发布于
2012/5/26
/
534
<div>public class ImageBorder extends AbstractBorder {</div> <div>Image top_center, top_left, top_right; Image left_center, right_center; Image bottom_center, bottom_left, bottom_right; Insets insets;</div> <div>public ImageBorder(Image top_left, Image top_center, Image top_right, Image left_center, Image right_center, Image bottom_left, Image bottom_center, Image bottom_right) {</div> <div>this.top_left = top_left; this.top_center = top_center; this.top_right = top_right; this.left_center = left_center; this.right_center = right_center; this.bottom_left = bottom_left; this.bottom_center = bottom_center; this.bottom_right = bottom_right; } <div>public void setInsets(Insets insets) { this.insets = insets; } <div>public Insets getBorderInsets(Component c) { if(insets != null) { return insets; } else { return new Insets(top_center.getHeight(null), left_center.getWidth(null), bottom_center.getHeight(null), right_center.getWidth(null)); } } <div>public BufferedImage createBufferedImage(Image img) { BufferedImage buff = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics gfx = buff.createGraphics(); gfx.drawImage(img, 0, 0, null); gfx.dispose(); return buff; } <div>public void fillTexture(Graphics2D g2, Image img, int x, int y, int w, int h) { BufferedImage buff = createBufferedImage(img); Rectangle anchor = new Rectangle(x,y,img.getWidth(null),img. getHeight(null)); TexturePaint paint = new TexturePaint(buff,anchor); g2.setPaint(paint); g2.fillRect(x,y,w,h); } <div>public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { g.setColor(Color.white); g.fillRect(x,y,width,height);</div> <div>Graphics2D g2 = (Graphics2D)g;</div> <div>int tlw = top_left.getWidth(null); int tlh = top_left.getHeight(null); int tcw = top_center.getWidth(null); int tch = top_center.getHeight(null); int trw = top_right.getWidth(null); int trh = top_right.getHeight(null);</div> <div>int lcw = left_center.getWidth(null); int lch = left_center.getHeight(null); int rcw = right_center.getWidth(null); int rch = right_center.getHeight(null); int blw = bottom_left.getWidth(null); int blh = bottom_left.getHeight(null); int bcw = bottom_center.getWidth(null); int bch = bottom_center.getHeight(null); int brw = bottom_right.getWidth(null); int brh = bottom_right.getHeight(null); fillTexture(g2,top_left,x,y,tlw,tlh); fillTexture(g2,top_center,x+tlw,y,width-tlw-trw,tch); fillTexture(g2,top_right,x+width-trw,y,trw,trh); fillTexture(g2,left_center,x,y+tlh,lcw,height-tlh-blh); fillTexture(g2,right_center,x+width-rcw,y+trh,rcw,height-trh-brh); fillTexture(g2,bottom_left,x,y+height-blh,blw,blh); fillTexture(g2,bottom_center,x+blw,y+height-bch,width-blw-brw,bch); fillTexture(g2,bottom_right,x+width-brw,y+height-brh,brw,brh); } } <div>public class ImageBorderHack {</div> <div>public static void main(String[] args) { JFrame frame = new JFrame("Hack #3: Fill Your Borders with Pretty Pictures"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); JButton button = new JButton("Image Border Test"); panel.add(button);</div> <div>ImageBorder image_border = new ImageBorder( new ImageIcon("images/upper_left.png").getImage(), new ImageIcon("images/upper.png").getImage(), new ImageIcon("images/upper_right.png").getImage(),</div> <div>new ImageIcon("images/left_center.png").getImage(), new ImageIcon("images/right_center.png").getImage(), new ImageIcon("images/bottom_left.png").getImage(), new ImageIcon("images/bottom_center.png").getImage(), new ImageIcon("images/bottom_right.png").getImage() ); panel.setBorder(image_border);</div> <div>frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true); } <div>}
试试其它关键字
以图片填充边框
同语言下
.
List 切割成几份 工具类
.
一行一行读取txt的内容
.
Java PDF转换成图片并输出给前台展示
.
java 多线程框架
.
double类型如果小数点后为零则显示整数否则保留两位小
.
将图片转换为Base64字符串公共类抽取
.
sqlParser 处理SQL(增删改查) 替换schema 用于多租户
.
JAVA 月份中的第几周处理 1-7属于第一周 依次类推 29-
.
java计算两个经纬度之间的距离
.
输入时间参数计算年龄
可能有用的
.
实现测量程序运行时间及cpu使用时间
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
DDT
贡献的其它代码
(
160
)
.
Oracle统计表的数据行和数据块信息
.
html标签闭合检测与修复
.
Powershell日期计算
.
Powershell的Base64编解码
.
Powershell并行循环
.
Powershell目录中搜索文本
.
Powershell枚举远程机器上的本地权限组
.
VBScript解析csv文件
.
快速排序之Powershell
.
批处理输出格式化时间字符串
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3