extending BufferedImage

后端 未结 2 2062
伪装坚强ぢ
伪装坚强ぢ 2021-01-22 14:32

Why does the following code show a black image instead of the picture? How to properly extend BufferedImage?

class SizeOfImage {

    public static void main(Str         


        
2条回答
  •  梦毁少年i
    2021-01-22 15:35

    Probably because the downloaded image bi is never drawn onto the cstImg.

    This line:

    CustomImg cstImg = new CustomImg(bi.getWidth(), bi.getHeight(), bi.getType());
    

    creates a new image based on the width, height and type of bi... not the content of bi. For that you probably want to do something like

    cstImg.getGraphics().drawImage(bi, 0, 0, null);
    

提交回复
热议问题