public static boolean write(RenderedImage im,
String formatName, //这个参数是什么意思,是文件名吗?
File output)
throws IOException
String formatName, //这个参数是什么意思,是文件名吗?
File output)
throws IOException
解决方案 »
- 一个ServerSocket 服务端在同一个端口上能并发的连接20个客户端吗?
- 很简单的java问题 谢谢高手们了
- 关于static ,final修饰函数
- 何如从网页中提取内容放入RDF文档中,how to scrape information from web site?
- java读取word文档,高手指教!
- 怎样实现这个小功能啊?
- 兄弟们,FileInputStream的read(byte b[],int off,int len)中的那个关于偏移量的参数int off该怎么用啊?
- 这种要求的dtd该怎么写啊?
- JAVA开发的程序怎么移植到客户端?
- 有关显示风格!!!(内详)
- 给位高手帮帮忙啊。。。。关于内部类的问题
- line.trim().equals("")什么意思
String formatName,
File output)
throws IOException使用支持给定格式的任意 ImageWriter 将一个图像写入 File。如果已经有一个 File 存在,则丢弃其内容。 参数:
im - 要写入的 RenderedImage。
formatName - 包含格式非正式名称的 String。
output - 将在其中写入数据的 File。
返回:
如果没有找到合适的 writer,则返回 false。
抛出:
IllegalArgumentException - 如果任何参数为 null。
IOException - 如果在写入过程中发生错误。
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;
}
}
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"));
//为什么这句话,写入文件时,文件总是无法成功写入,这是为什么??高手,救我。
}
}
// 原图的大小
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;
}
}
把jpg改成JPEG