How to convert buffered image to image and vice-versa?

后端 未结 6 586

Actually i am working on a image editing software and now i want to convert the buffered-image i.e :

  BufferedImage buffer = ImageIO.read(new File(file));
<         


        
6条回答
  •  萌比男神i
    2020-12-05 14:46

    Example: say you have an 'image' you want to scale you will need a bufferedImage probably, and probably will be starting out with just 'Image' object. So this works I think... The AVATAR_SIZE is the target width we want our image to be:

    Image imgData = image.getScaledInstance(Constants.AVATAR_SIZE, -1, Image.SCALE_SMOOTH);     
    
    BufferedImage bufferedImage = new BufferedImage(imgData.getWidth(null), imgData.getHeight(null), BufferedImage.TYPE_INT_RGB);
    
    bufferedImage.getGraphics().drawImage(imgData, 0, 0, null);
    

提交回复
热议问题