(1)如果设置为int,上面的if就会变成(0<=0)了 (2)算法确实很简单,我们一般取比例值较小的 4,将上面的所得的width,height转化为int型
- 开发无止境 -
Data: 2018-06-26 20:21:35Form: JournalClick: 14
在许多语言中,都希望图片可以等比例缩小或者放大,但是仅仅依靠语言本身的方法,大多差强人意,所以在此提供一个所有语言通用的图片等比例缩小方法的算法。这里以java语言为例子
1.给两个值,设置你想要设置图片的宽和高;定义两个真正的宽和高;这里定义为double 类型
double imageWidth=image.getIconWidth();
double imageHeight=image.getIconHeight();
3.写出算法
if(setWidth/imageWidth<=setHeight/imageHeight){
width=imageWidth*(setWidth/imageWidth);
height=imageHeight*(setWidth/imageWidth);
}else{
width=imageWidth*(setHeight/imageHeight);
height=imageHeight*(setHeight/imageHeight);
}