可能重复:
在 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));
}
}
我没问题,但根据图片,我在对灰色部分进行采样时遇到了问题!!!!