计算两个日期内相隔的天数 and 旋转图片

/**
* 计算两个日期内相隔的天数
* @param fDate
* @param oDate
* @return
*/
public static int daysOfTwo(Date fDate,Date oDate)
{
//首先定义一个calendar,必须使用getInstance()进行实例化
Calendar aCalendar=Calendar.getInstance();
//里面野可以直接插入date类型
aCalendar.setTime(fDate);
//计算此日期是一年中的哪一天
int day1=aCalendar.get(Calendar.DAY_OF_YEAR);
aCalendar.setTime(oDate);
int day2=aCalendar.get(Calendar.DAY_OF_YEAR);
//求出两日期相隔天数
int days=day2-day1;
return days;
}
/**
* 旋转图片
* @param filePath 图片路径
* @param degree 旋转角度 最好是90或者是90的倍数
* @param bgcolor 设置图片的背景色
*/
public static void rotateImg1(String filePath,int degree, Color bgcolor ){
String path = "f:\\t.jpg";
File img = new File(path);
try {
BufferedImage image = (BufferedImage)ImageIO.read(img);
int iw = image.getWidth();//原始图象的宽度
int ih = image.getHeight();//原始图象的高度
int w=0;
int h=0;
int x=0;
int y=0;
degree=degree%360;
if(degree<0)degree=360+degree;//将角度转换到0-360度之间
double ang=degree* 0.0174532925;//将角度转为弧度

/**
*确定旋转后的图象的高度和宽度
*/

if(degree == 180|| degree == 0 || degree == 360){
w = iw;
h = ih;
}else if(degree == 90|| degree == 270){
w = ih;
h = iw;
}else{
int d=iw+ih;
w=(int)(d*Math.abs(Math.cos(ang)));
h=(int)(d*Math.abs(Math.sin(ang)));
}

x = (w/2)-(iw/2);//确定原点坐标
y = (h/2)-(ih/2);
BufferedImage rotatedImage=new BufferedImage(w,h,image.getType());
Graphics gs=rotatedImage.getGraphics();
gs.setColor(bgcolor);
gs.fillRect(0,0,w,h);//以给定颜色绘制旋转后图片的背景
AffineTransform at=new AffineTransform();
at.rotate(ang,w/2,h/2);//旋转图象
at.translate(x,y);
AffineTransformOp op=new AffineTransformOp(at,AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
op.filter(image, rotatedImage);
BufferedImage new_img = rotatedImage;
FileOutputStream out = new FileOutputStream(path);
try{
ImageIO.write(new_img, "JPG", out);
}finally{
out.close();
}
} catch (Exception e) {
e.printStackTrace();
}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值