@Test public void changeSize() { String srcPath = "C:\\Users\\Administrator\\Desktop\\test_img_store\\old\\AppIcon57x57.png"; String destPath = "C:\\Users\\Administrator\\Desktop\\test_img_store\\new\\2_AppIcon512x512.png"; FileCommonUtil.changeSize(srcPath, destPath, 512, 512); }
public static boolean changeSize(String srcPath, String destPath, int newWidth, int newHeight) { try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(srcPath)); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(destPath))) { Image image = ImageIO.read(in); BufferedImage bufferedImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB); bufferedImage.getGraphics().drawImage(image, 0, 0, newWidth, newHeight, null); ImageIO.write(bufferedImage, "PNG", out); return true; } catch (IOException e) { logger.error("changeSize, IOException: [{}]", e); return false; } }
FileCommonUtil { public static boolean changeSize(String srcPath, String destPath, int newWidth, int newHeight) { try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(srcPath)); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(destPath))) { Image image = ImageIO.read(in); BufferedImage bufferedImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB); bufferedImage.getGraphics().drawImage(image, 0, 0, newWidth, newHeight, null); ImageIO.write(bufferedImage, "PNG", out); return true; } catch (IOException e) { logger.error("changeSize, IOException: [{}]", e); return false; } } }
FileCommonUtil { public static boolean changeSize(String srcPath, String destPath, int newWidth, int newHeight) { try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(srcPath)); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(destPath))) { Image image = ImageIO.read(in); BufferedImage bufferedImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB); bufferedImage.getGraphics().drawImage(image, 0, 0, newWidth, newHeight, null); ImageIO.write(bufferedImage, "PNG", out); return true; } catch (IOException e) { logger.error("changeSize, IOException: [{}]", e); return false; } }  }
FileCommonUtil { public static boolean changeSize(String srcPath, String destPath, int newWidth, int newHeight) { try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(srcPath)); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(destPath))) { Image image = ImageIO.read(in); BufferedImage bufferedImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB); bufferedImage.getGraphics().drawImage(image, 0, 0, newWidth, newHeight, null); ImageIO.write(bufferedImage, "PNG", out); return true; } catch (IOException e) { logger.error("changeSize, IOException: [{}]", e); return false; } }  static boolean isFileSizeLegal(int length, Double maxSize); static String generateMappingPath(String rootPath, String hash, String nameSuffix); static byte[] encryptImgXor(byte[] fileBytes, int xor); static String getContent(File file); static boolean resizeImage(String srcPath, String destPath, int newWidth, int newHeight, boolean forceSize); static boolean changeSize(String srcPath, String destPath, int newWidth, int newHeight); static boolean compressToTar(File inputFile, String outFilePath); }
FileCommonUtil { public static boolean changeSize(String srcPath, String destPath, int newWidth, int newHeight) { try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(srcPath)); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(destPath))) { Image image = ImageIO.read(in); BufferedImage bufferedImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB); bufferedImage.getGraphics().drawImage(image, 0, 0, newWidth, newHeight, null); ImageIO.write(bufferedImage, "PNG", out); return true; } catch (IOException e) { logger.error("changeSize, IOException: [{}]", e); return false; } }  static boolean isFileSizeLegal(int length, Double maxSize); static String generateMappingPath(String rootPath, String hash, String nameSuffix); static byte[] encryptImgXor(byte[] fileBytes, int xor); static String getContent(File file); static boolean resizeImage(String srcPath, String destPath, int newWidth, int newHeight, boolean forceSize); static boolean changeSize(String srcPath, String destPath, int newWidth, int newHeight); static boolean compressToTar(File inputFile, String outFilePath);  }