可能重复: 调整Java中的图像大小-任何开源库?
我希望我能在录制前调整图像的大小!我试了几次,但没有成功。你能告诉我手术程序吗。我想使用imgscarlr或更好的。谢谢
private static void getImages(String src,String Name) throws IOException {
String folder = null;
//Exctract the name of the image from the src attribute
int indexname = src.lastIndexOf("/");
if (indexname == src.length()) {
src = src.substring(1, indexname);
}
indexname = src.lastIndexOf("/");
String name = src.substring(indexname, src.length());
System.out.println(name);
//Open a URL Stream
URL url = new URL(src);
InputStream in = url.openStream();
OutputStream out = new BufferedOutputStream(new FileOutputStream( folderPath+ name));
for (int b; (b = in.read()) != -1;) {
out.write(b);
}
BufferedImage originalImage = ImageIO.read(new File(folderPath+name));
BufferedImage scaledImage = Scalr.resize(originalImage, 200);
ImageIO.write(scaledImage, "jpg", new File(folderPath+name));
}
}我没事,但根据图片,我有一个问题,采样灰色部分!
发布于 2012-07-24 09:21:21
您需要首先“加载”映像,查看ImageIO API以获得更多细节,然后,根据您的需要,缩放映像相对简单
更新
从URL读取图像
图像缩放API
多步、高质量的缩放
发布于 2012-07-25 07:08:09
我忘了out.close();现在是工作了
https://stackoverflow.com/questions/11627646
复制相似问题