/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.oim.common.util;
import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.Toolkit;
import java.awt.Transparency;
import java.awt.geom.AffineTransform;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.ConvolveOp;
import java.awt.image.Kernel;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
/**
*
* @author Hero
*/
public class ImageUtil {
public static ImageIcon getImageIconByPath(String imagePath, int w, int h) {
ImageIcon imageIcon = null;
if (!"".equals(imagePath)) {
imageIcon = getImageIcon(imagePath);
if (null != imageIcon) {
int width = imageIcon.getIconWidth();
int height = imageIcon.getIconHeight();
float xbili = (float) ((w * 1.0) / width);
float ybili = (float) ((h * 1.0) / height);
float bili = xbili > ybili ? ybili : xbili;
int newwidth = (int) (width * bili);
int newheight = (int) (height * bili);
Image image = getImage(imagePath, newwidth, newheight);
imageIcon.setImage(image);
}
}
return imageIcon;
}
public static Image getImage(String path) {
return Toolkit.getDefaultToolkit().getImage(path);
}
public static Image getImage(String path, int w, int h) {
Image image = getImage(path);
if (null != image) {
image = image.getScaledInstance(w, h, Image.SCALE_SMOOTH);
}
return image;
}
public static Icon getIcon(String path) {
return getImageIcon(path);
}
public static Icon getIcon(String path, int w, int h) {
return getImageIcon(path, w, h);
}
public static ImageIcon getImageIcon(String path) {
Image image = getImage(path);
if (null != image) {
return new ImageIcon(image);
}
return null;
}
public static ImageIcon getImageIcon(String path, int w, int h) {
Image image = getImage(path, w, h);
if (null != image) {
return new ImageIcon(image);
}
return null;
}
public static Image getRoundedCornerImage(String imagePath, int width, int height, int cornersWidth, int cornerHeight) {
Image image = getRoundedCornerBufferedImage(imagePath, width, height, cornersWidth, cornerHeight);
return image;
}
public static Icon getRoundedCornerIcon(String imagePath, int width, int height, int cornersWidth, int cornerHeight) {
return getRoundedCornerImageIcon(imagePath, width, height, cornersWidth, cornerHeight);
}
public static ImageIcon getRoundedCornerImageIcon(String imagePath, int width, int height, int cornersWidth, int cornerHeight) {
BufferedImage image = getRoundedCornerBufferedImage(imagePath, width, height, cornersWidth, cornerHeight);
if (null == image) {
return null;
}
ImageIcon icon = new ImageIcon();
icon.setImage(image);
return icon;
}
public static BufferedImage getRoundedCornerBufferedImage(String imagePath, int width, int height, int cornersWidth, int cornerHeight) {
try {
File imageFile = new File(imagePath);
if (imageFile.exists()) {
BufferedImage image = ImageIO.read(imageFile); // BufferedImage)
// Toolkit.getDefaultToolkit().getImage(imagePath);
int w = image.getWidth();
int h = image.getHeight();
if (0 != width && 0 < width) {
w = width;
}
if (0 != height && 0 < height) {
h = height;
}
BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = output.createGraphics();
g2.setComposite(AlphaComposite.Src);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// g2.setColor(new Color(0,0,0));
// g2.setBackground(Color);
g2.setStroke(new BasicStroke(1));
g2.fillRoundRect(0, 0, w, h, cornersWidth, cornerHeight);
// g2.setComposite(AlphaComposite.Src);
// g2.fill(new RoundRectangle2D.Float(0, 0, w, h, cornersWidth,
// cornerHeight));
g2.setComposite(AlphaComposite.SrcAtop);
// g2.setColor(Color.white);//这里设置背景颜色
// g2.fillRect(0, 0, w, h);//这里填充背景颜色
g2.drawImage(image, 0, 0, w, h, null);
g2.dispose();
return output;
}
} catch (IOException ex) {
Logger.getLogger(ImageUtil.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
public static Image getRoundedCornerImage(Image image, int width, int height, int cornersWidth, int cornerHeight) {
return getRoundedCornerBufferedImage(imageToBufferImage(image), width, height, cornersWidth, cornerHeight);
}
public static Icon getRoundedCornerIcon(Image image, int width, int height, int cornersWidth, int cornerHeight) {
return getRoundedCornerImageIcon(imageToBufferImage(image), width, height, cornersWidth, cornerHeight);
}
public static ImageIcon getRoundedCornerImageIcon(Image image, int width, int height, int cornersWidth, int cornerHeight) {
BufferedImage bufferedImage = getRoundedCornerBufferedImage(imageToBufferImage(image), width, height, cornersWidth, cornerHeight);
if (null == bufferedImage) {
return null;
}
ImageIcon icon = new ImageIcon();
icon.setImage(bufferedImage);
return icon;
}
public static BufferedImage getRoundedCornerBufferedImage(BufferedImage image, int width, int height, int cornersWidth, int cornerHeight) {
int w = image.getWidth();
int h = image.getHeight();
if (0 != width && 0 < width) {
w = width;
}
if (0 != height && 0 < height) {
h = height;
}
BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = output.createGraphics();
g2.setComposite(AlphaComposite.Src);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// g2.setColor(new Color(0,0,0));
// g2.setBackground(Color);
g2.setStroke(new BasicStroke(1));
g2.fillRoundRect(0, 0, w, h, cornersWidth, cornerHeight);
// g2.setComposite(AlphaComposite.Src);
// g2.fill(new RoundRectangle2D.Float(0, 0, w, h, cornersWidth,
// cornerHeight));
g2.setComposite(AlphaComposite.SrcAtop);
// g2.setColor(Color.white);//这里设置背景颜色
// g2.fillRect(0, 0, w, h);//这里填充背景颜色
g2.drawImage(image, 0, 0, w, h, null);
g2.dispose();
return output;
}
public static BufferedImage imageToBufferImage(Image image) {
BufferedImage bimage = null;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
try {
// int transparency = Transparency.OPAQUE;
int transparency = Transparency.TRANSLUCENT;
GraphicsDevice gs = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gs.getDefaultConfiguration();
bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency);
} catch (HeadlessException e) {
return bimage;
}
if (bimage == null) {
int type = BufferedImage.TYPE_INT_RGB;
bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
}
// Graphics g = bimage.createGraphics();
// g.drawImage(image, 0, 0, null);
// g.dispose();
return bimage;
}
public static BufferedImage getBufferedImage(String image, int alpha) {
if (null != image && !"".equals(image)) {
BufferedImage bufferedImage = null;
FileInputStream stream =null;
try
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
这是我对原来山寨QQ的进一步改进,其实功能什么的都好多还没实现,改进主要是在工作中遇到的一些经验应用到其中,所以主要的改进在代码上,模块之间的耦合度,程序的层次更明显等改进,由于工作没啥业余时间,暂时就只有实现了:注册、登录、查找用户、添加用户、聊天等基本功能。希望能帮到有兴趣的人。
资源推荐
资源详情
资源评论
收起资源包目录
Java Swing 扁平化的聊天程序源码 (2000个子文件)
81_16.bmp 517B
39_16.bmp 500B
95_16.bmp 497B
29_16.bmp 474B
38_16.bmp 474B
37_16.bmp 470B
30_16.bmp 469B
18_16.bmp 466B
3_16.bmp 462B
60_16.bmp 461B
28_16.bmp 459B
5_16.bmp 457B
84_16.bmp 452B
34_16.bmp 446B
22_16.bmp 442B
36_16.bmp 438B
51_16.bmp 437B
83_16.bmp 433B
62_16.bmp 433B
97_16.bmp 432B
55_16.bmp 428B
100_16.bmp 427B
59_16.bmp 426B
61_16.bmp 425B
85_16.bmp 422B
79_16.bmp 417B
40_16.bmp 416B
45_16.bmp 409B
33_16.bmp 406B
78_16.bmp 405B
41_16.bmp 404B
43_16.bmp 400B
27_16.bmp 399B
35_16.bmp 398B
80_16.bmp 390B
63_16.bmp 385B
42_16.bmp 384B
48_16.bmp 382B
1_16.bmp 381B
72_16.bmp 381B
82_16.bmp 379B
98_16.bmp 378B
53_16.bmp 375B
67_16.bmp 373B
96_16.bmp 371B
64_16.bmp 371B
101_16.bmp 371B
52_16.bmp 370B
49_16.bmp 368B
68_16.bmp 366B
73_16.bmp 366B
58_16.bmp 364B
19_16.bmp 362B
47_16.bmp 362B
50_16.bmp 360B
46_16.bmp 356B
44_16.bmp 349B
71_16.bmp 347B
70_16.bmp 346B
94_16.bmp 345B
57_16.bmp 342B
77_16.bmp 340B
92_16.bmp 337B
25_16.bmp 327B
54_16.bmp 323B
99_16.bmp 323B
93_16.bmp 318B
75_16.bmp 310B
88_16.bmp 308B
87_16.bmp 301B
23_16.bmp 301B
32_16.bmp 294B
17_16.bmp 294B
86_16.bmp 290B
24_16.bmp 289B
74_16.bmp 285B
90_16.bmp 283B
66_16.bmp 277B
91_16.bmp 272B
89_16.bmp 268B
20_16.bmp 265B
26_16.bmp 265B
15_16.bmp 264B
56_16.bmp 262B
8_16.bmp 261B
76_16.bmp 260B
10_16.bmp 260B
14_16.bmp 254B
12_16.bmp 249B
9_16.bmp 247B
16_16.bmp 246B
7_16.bmp 244B
11_16.bmp 239B
31_16.bmp 238B
13_16.bmp 237B
65_16.bmp 236B
21_16.bmp 233B
6_16.bmp 232B
2_16.bmp 229B
4_16.bmp 228B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
烙灵
- 粉丝: 51
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页