|
|
|
@ -283,6 +283,29 @@ public class Files { |
|
|
|
return os.toByteArray(); |
|
|
|
} |
|
|
|
|
|
|
|
public static BufferedImage bytesTobufferedImage(byte[] bytes){ |
|
|
|
BufferedImage image = null; |
|
|
|
|
|
|
|
try { |
|
|
|
// 利用ByteArrayInputStream将字节数据转换成InputStream
|
|
|
|
ByteArrayInputStream bais = new ByteArrayInputStream(bytes); |
|
|
|
|
|
|
|
// 使用ImageIO读取InputStream中的数据转换为BufferedImage
|
|
|
|
image = ImageIO.read(bais); |
|
|
|
|
|
|
|
// 关闭ByteArrayInputStream
|
|
|
|
bais.close(); |
|
|
|
// 此时,image就是转换后的BufferedImage对象,可以进行显示或其他处理
|
|
|
|
// 例如显示图像:
|
|
|
|
// ImageIcon icon=new ImageIcon(image);
|
|
|
|
// JOptionPane.showMessageDialog(null, icon);
|
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return image; |
|
|
|
} |
|
|
|
|
|
|
|
public static String uploadImage(BufferedImage bufferedImage,String imgPath,String rqImg) throws Exception{ |
|
|
|
File file =new File(imgPath+rqImg); |
|
|
|
if(!file.getParentFile().exists()){ |
|
|
|
|