2016-05-26 9 views
1

私はBufferedImagesのサイズを変更する方法を書いていましたが、その後に.pngイメージが透明になり、代わりに黒い背景が表示されます。サイズ変更後に黒い背景を削除する方法

public BufferedImage getSizedImg(BufferedImage otherImage,int width,int height){ 
    BufferedImage outputImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 

    Graphics g = outputImg.createGraphics(); 
    g.drawImage(otherImage, 0, 0, width, height, null); 
    g.dispose(); 
    return outputImg; 
} 

どのように画像を透明に保つようにこのメソッドを修正できますか?

答えて

4

シンプルです。あなたがここにあなたの新しい再サイズのBufferedImageを作成する場合:

BufferedImage outputImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 

BufferedImage.TYPE_INT_RGBではなくBufferedImage.TYPE_INT_ARGBを使用しないでください。 "A"は "アルファ"の略で、これはあなたに透明性を与えます。詳細についてはBufferedImage APIをご覧ください。

関連する問題