package imageUpdate;
import java.awt.image.BufferedImage;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.imageio.ImageIO;
public class ImageUtil {
public static void main(String arg[])
{
String filePath = "C:\\Users\\CYT\\Desktop\\today\\images\\error.gif"; // 图片的位置
int height=30;
int width=30;
Icon icon = null;
try
{
icon = getRatioWidth(filePath,width);
}
catch(Exception e)
{
System.out.println("exception : " +e);
}
System.out.println(" ### " +icon); //生成新图片的位置;
}
/**
* 按宽的比例更改图片的大小
* @param filePath 图片路径
* @param width 需要改变图片的宽度
* @return
* @throws Exception
*/
public static Icon getRatioWidth(String filePath, int width) throws Exception{
File f = new File(filePath);
BufferedImage bi = ImageIO.read(f);
double wRatio = (new Integer(width)).doubleValue() / bi.getWidth(); //宽度的比例
int height = (int)(wRatio * bi.getHeight()); //图片转换后的高度
Image image = bi.getScaledInstance(width,height,Image.SCALE_SMOOTH); //设置图像的缩放大小
AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(wRatio,wRatio),null); //设置图像的缩放比例
image = op.filter(bi,null);
int lastLength = filePath.lastIndexOf(".");
String subFilePath = filePath.substring(0,lastLength); //得到图片输出路径
String fileType = filePath.substring(lastLength); //图片类型
String type=filePath.substring(lastLength+1); //图片类型 不包括点
File zoomFile = new File(subFilePath +"_" + fileType);
Icon ret = null;
try
{
ImageIO.write((BufferedImage)image, type, zoomFile);
ret = new ImageIcon(zoomFile.getPath());
}
catch (Exception e)
{
e.printStackTrace();
}
return ret;
}
/**
* 按高的比例更改图片大小
* @param filePath 图片路径
* @param height 需要改变图片的高度
* @return
* @throws Exception
*/
public static Icon getRatioHeight(String filePath, int height) throws Exception{
File f = new File(filePath);
BufferedImage bi = ImageIO.read(f);
double hRatio = (new Integer(height)).doubleValue() / bi.getHeight(); //高度的比例
int width = (int)(hRatio * bi.getWidth()); //图片转换后的高度
Image image = bi.getScaledInstance(width,height,Image.SCALE_SMOOTH); //设置图像的缩放大小
AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(hRatio,hRatio),null); //设置图像的缩放比例
image = op.filter(bi,null);
int lastLength = filePath.lastIndexOf(".");
String subFilePath = filePath.substring(0,lastLength); //得到图片输出路径
String fileType = filePath.substring(lastLength); //图片类型
File zoomFile = new File(subFilePath +"_" + fileType);
Icon ret = null;
try
{
ImageIO.write((BufferedImage)image, fileType, zoomFile);
ret = new ImageIcon(zoomFile.getPath());
}
catch (Exception e)
{
e.printStackTrace();
}
return ret;
}
/**
* 按输入的任意宽高改变图片的大小
* @param filePath
* @param width
* @param height
* @return
* @throws Exception
*/
public static Icon getFixedIcon(String filePath, int width, int height) throws Exception{
File f = new File(filePath);
BufferedImage bi = ImageIO.read(f);
double wRatio = (new Integer(width)).doubleValue() / bi.getWidth(); //宽度的比例
double hRatio = (new Integer(height)).doubleValue() / bi.getHeight(); //高度的比例
Image image = bi.getScaledInstance(width,height,Image.SCALE_SMOOTH); //设置图像的缩放大小
AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(wRatio,hRatio),null); //设置图像的缩放比例
image = op.filter(bi,null);
int lastLength = filePath.lastIndexOf(".");
String subFilePath = filePath.substring(0,lastLength); //得到图片输出路径
String fileType = filePath.substring(lastLength); //图片类型
String type=filePath.substring(lastLength+1); //图片类型 不包括点
File zoomFile = new File(subFilePath +"_" + fileType);
Icon ret = null;
try
{
ImageIO.write((BufferedImage)image, type, zoomFile);
ret = new ImageIcon(zoomFile.getPath());
}
catch (Exception e)
{
e.printStackTrace();
}
return ret;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于jsp+servlet电子商城
共2000个文件
gif:701个
svn-base:427个
png:241个
4星 · 超过85%的资源 需积分: 12 68 下载量 142 浏览量
2012-11-29
13:16:32
上传
评论 6
收藏 17.44MB ZIP 举报
温馨提示
完整的电子商城网站!包括用户注册(邮箱验证),登录,购物车功能,搜索功能,用户评论功能。后台管理员上传商品,对各表数据增删改查。 使用jsp + servlet ,数据库使用sqlserver 2005 本人是初学JSP由自己独立完成,现分享给大家,如果有初学jsp的朋友,可以看看!
资源推荐
资源详情
资源评论
收起资源包目录
基于jsp+servlet电子商城 (2000个子文件)
all-wcprops 16KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 1KB
all-wcprops 904B
all-wcprops 846B
all-wcprops 813B
all-wcprops 808B
all-wcprops 783B
all-wcprops 692B
all-wcprops 649B
all-wcprops 562B
all-wcprops 530B
all-wcprops 460B
all-wcprops 432B
all-wcprops 428B
all-wcprops 410B
all-wcprops 347B
all-wcprops 309B
all-wcprops 299B
all-wcprops 292B
all-wcprops 234B
all-wcprops 224B
all-wcprops 222B
all-wcprops 218B
all-wcprops 208B
all-wcprops 200B
all-wcprops 174B
all-wcprops 84B
all-wcprops 83B
all-wcprops 81B
all-wcprops 79B
all-wcprops 77B
all-wcprops 70B
ScriptResource.axd 254KB
ScriptResource.axd 254KB
ScriptResource(1).axd 64KB
ScriptResource(1).axd 64KB
WebResource.axd 20KB
WebResource.axd 20KB
ShopingController.class 4KB
GoodsAddServletController.class 4KB
RegisterController2.class 4KB
ImageUtil.class 4KB
FillInOrderServletController.class 4KB
UserInfoUpdateController.class 4KB
AdminUserInfoUpdateController.class 4KB
UserPasswordUpdate.class 3KB
UserInfo.class 3KB
GoodsInfoUpdateController.class 3KB
Util.class 3KB
FileUploadServlet.class 3KB
AddProductEvaluationtController.class 3KB
GoodsInfoSearchViewController.class 3KB
UserInfoViewController.class 3KB
AddOrderDetailServletController.class 3KB
SPCarController.class 3KB
AdminUserInfoViewController.class 3KB
AdminLoginController.class 3KB
LoginController.class 3KB
GoodsInfo.class 3KB
AccountControlle.class 3KB
OrderDetailUpdateController.class 2KB
OrderInfoUpdateController.class 2KB
DbDao.class 2KB
DelAllProductController.class 2KB
OneGoodsInfoViewController.class 2KB
ToProductDedatilViewController.class 2KB
AllUserInfoView.class 2KB
AdminViewOrderDetailController.class 2KB
AdminViewOrderDetailController.class 2KB
RegisterController.class 2KB
ViewOrderDetailController.class 2KB
AdminGoodsEvaluationUpdateController.class 2KB
ViewOrderController.class 2KB
OneUserInfoView.class 2KB
GoodsView.class 2KB
GoodsInfoDeleteController.class 2KB
SendAuthNum.class 2KB
GoodsEvaluationViewController.class 2KB
UserOrderInfo.class 2KB
OneGoodsEvaluationViewController.class 2KB
AdminRegisterController.class 2KB
delCarControlle.class 2KB
OrderDetailDeleteController.class 2KB
GoodsInfoViewController.class 2KB
UserOrderView.class 2KB
IndexGoodsInfoViewController.class 2KB
AdminViewOrderController.class 2KB
AdminViewOrderController.class 2KB
UserOrderDetailView.class 2KB
GoodsEvaluationView.class 2KB
AdminGoodsEvaluationViewController.class 2KB
AdminGoodsEvaluationDeleteController.class 2KB
ViewAllUserController.class 2KB
DetailController.class 2KB
OrderInfoDeleteController.class 2KB
UserInfoDeleteController.class 2KB
UserOrderDetail.class 2KB
GetConnListener.class 2KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
零点更新
- 粉丝: 0
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页