[英]How to convert images already stored in MySQL database to images stored locally
我已经使用Java和MySQL构建了一个软件。 它的功能是接收图像并将其存储到数据库(MySQL)中。 我这样做是为了方便备份。 但是现在我意识到对数据库的压力正在增加。 因此,我决定将数据库中当前约306行的所有图像转换为本地图像,并将其存储在系统中。 我该如何处理,以避免重新输入数据?
使用以下代码检索所有图像并将其保存在本地:
通过使用从表中选择图像
然后在LOOP中使用此代码
private static void save(BufferedImage image, String fileName,String ext) {
File file = new File(fileName + "." + ext);
try {
ImageIO.write(image, ext, file); // ignore returned boolean
} catch(IOException e) {
System.out.println("Write error for " + file.getPath() +
": " + e.getMessage());
}
}
private static BufferedImage toBufferedImage(Image src) {
int w = src.getWidth(null);
int h = src.getHeight(null);
int type = BufferedImage.TYPE_INT_RGB; // other options
BufferedImage dest = new BufferedImage(w, h, type);
Graphics2D g2 = dest.createGraphics();
g2.drawImage(src, 0, 0, null);
g2.dispose();
return dest;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.