62,614
社区成员
发帖
与我相关
我的任务
分享
if (width > 0 || hight > 0) {
// 原图的大小
int sw = srcImage.getWidth();
int sh = srcImage.getHeight();
// 如果原图像的大小小于要缩放的图像大小,直接将要缩放的图像复制过去
if (sw > width && sh > hight) {
srcImage = resize(srcImage, width, hight);
} else {
String fileName = saveFile.getName();
String formatName = fileName.substring(fileName
.lastIndexOf('.') + 1);
ImageIO.write(srcImage, formatName, saveFile);
return;
}
}
mport java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Img
{
static BufferedImage bufImg ;
public static void main(String[] args) throws IOException
{
try
{
bufImg = ImageIO.read(new File("g:\\tt.jpg"));
}catch(Exception e)
{}
int a = bufImg.getRGB(0, 0);
System.out.println("a1="+a);
a = bufImg.getRGB(0, 1);
System.out.println("a2="+a);
a = bufImg.getRGB(1, 0);
System.out.println("a3="+a);
a = bufImg.getRGB(1, 1);
System.out.println("a4="+a);
bufImg.setRGB(0,1,-1);
ImageIO.write(bufImg, ".jpg", new File("g:\\tt.jpg"));
//为什么这句话,写入文件时,文件总是无法成功写入,这是为什么??高手,救我。
}
}