¼òµ¥µÄjavaͼƬËõ·Å´úÂë
/**
* @param source: source image file
* @param output: output image file
* @param mode: 0 ratio,1 maxWidth,2 maxHeight,3 maxSide
* @param maxSide: maxWidth, maxHeight or maxSide, different by mode
* @param ratio: ratio if resized by ratio
*/
public static void resizeImage(File source, File output, int mode, Integer maxSide, Double ratio)
throws IOException {
// read image
Image sourceImage = ImageIO.read(source);
// resize image
BufferedImage outputImage = getResizeImage(sourceImage, mode, maxSide, ratio);
// wirite image to file
wirteImageToFile(outputImage, output);
}
/**
* @param source: source image
* @param mode: 0 ratio,1 maxWidth,2 maxHeight,3 maxSide
* @param maxSide: maxWidth, maxHeight or maxSide, different by mode
* @param ratio: ratio if resized by ratio
*/
public static BufferedImage getResizeImage(Image source, int mode, Integer maxSide, Double ratio) {
int srcImageWidth = source.getWidth(null);
int srcImageHeight = source.getHeight(null);
int width = 0, height = 0;
switch (mode) {
case 0:
// resize by ratio
width = (int) (srcImageWidth * ratio);
height = (int) (srcImageHeight * ratio);
break;
case 1:
// resize by max width
width = maxSide;
height = new BigDecimal(srcImageHeight).divide(new BigDecimal(srcImageWidth), 5, RoundingMode.HALF_EVEN)
.multiply(new BigDecimal(width)).intValue();
break;
case 2:
// resize by max height
height = maxSide;
width = new BigDecimal(srcImageWidth).divide(new BigDecimal(srcImageHeight), 5, RoundingMode.HALF_EVEN)
.multiply(new BigDecimal(height)).intValue();
break;
case 3:
// resize by max side(between width and height)
if (srcImageWidth > srcImageHeight) {
width = maxSide;
height = maxSide * srcImageHeight / srcImageWidth;
} else {
width = maxSide * srcImageWidth / srcImageHeight;
height = maxSide;
}
break;
}
BufferedImage t
Ïà¹ØÎĵµ£º
1. byte Èç¹ûûÓи³Öµ£¬ÄÇôjava»á×Ô¶¯½«Ëü¸³ÖµÎª £¨byte£©0;
static String ReadLn (int maxLg) // utility function to read from stdin
{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
String line = "";
try
{
while (lg < maxLg)
......
public static void main(String args[]){
Date calr1=new Date(2010, 3,1);
Date calr2=new Date(2010,3,31);
Long n=calr2.getTime()-calr1.getTime();
int a=(int)(n/ ......
import java.io.*;
public class FileReaderSample {
public static void main(String args[]) throws IOException
{
// ½¨Á¢¿ÉÈÝÄÉ1024¸ö×Ö·ûµÄÊý×é
char data[]=new char[1024];
// ½¨Á¢¶ÔÏófr
FileReader fr= ......
import java.io.*;
public class FileWrite {
public static void main(String args[]) {
String outPut = "C:\\bin";
StringBuffer ab = new StringBuffer();
for(int i=6;i<=30;i++){
ab.append("http://www.test.com/joke/index_"+i+".htm\r\n&qu ......
ÄÚÈÝ£º
¡¡¡¡Ê²Ã´ÊÇ·´±àÒ룿
¡¡¡¡·´»ã±àÒ»¸öÀàÎļþ
¡¡¡¡Ê¹Ó÷´±àÒëÆ÷
¡¡¡¡·´±àÒëºÍ¶Ô°²È«µÄÍþв
¡¡¡¡Õë·æÏà¶ÔµÄ´úÂëÄ£ºý´¦Àí
¡¡¡¡ÕâÒ»ÁìÓòµÄгÉÔ±
¡¡¡¡×ܽá
¡¡¡¡²Î¿¼×ÊÁÏ
¡¡¡¡¹ØÓÚ×÷Õß
¡¡¡¡ÆÀ¼Û±¾ÎÄ
¡¡¡¡Ïà¹ØÄÚÈÝ£º
¡¡¡¡ÈÃÄúµÄÈí¼þÔËÐУºÄ£ºý°²È«ÐÔ
¡¡¡¡Java ºÍ·Ö²¼Ê½Ä¿±êϵͳÉϵݲȫÐÔÑо¿
¡ ......