プロジェクトでは、画像の不透明度を変更して同時に変更したいと考えています。これまでのところ、私はサイズを小さくしていると思う。画像の不透明度を変更する
public BufferedImage resizeImage(BufferedImage originalImage, int type){
initialWidth += 10;
initialHeight += 10;
BufferedImage resizedImage = new BufferedImage(initialWidth, initialHeight, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, initialWidth, initialHeight, null);
g.dispose();
return resizedImage;
}
私はここからこのコードを持って:私はサイズ変更を達成するためにそのように定義されたメソッドを使用します。私が解決策を見つけることができないのは、不透明度を変更することです。それは私が(もしそれが可能ならば)どうやってやろうとしているのかと思います。前もって感謝します。
UPDATE:
私は成長していると少なく不透明になってきて(画像下記参照)透明内側と外側の円の絵を表示するには、このコードを試してみましたが、それはうまくいきませんでした。私は何が間違っているのか分かりません。すべてのコードは、アニメーション
public Animation() throws IOException{
image = ImageIO.read(new File("circleAnimation.png"));
initialWidth = 50;
initialHeight = 50;
opacity = 1;
}
public BufferedImage animateCircle(BufferedImage originalImage, int type){
//The opacity exponentially decreases
opacity *= 0.8;
initialWidth += 10;
initialHeight += 10;
BufferedImage resizedImage = new BufferedImage(initialWidth, initialHeight, type);
Graphics2D g = resizedImage.createGraphics();
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));
g.drawImage(originalImage, 0, 0, initialWidth, initialHeight, null);
g.dispose();
return resizedImage;
}
と呼ばれるクラスである私はこのようにそれを呼び出す:
Animation animate = new Animation();
int type = animate.image.getType() == 0? BufferedImage.TYPE_INT_ARGB : animate.image.getType();
BufferedImage newImage;
while(animate.opacity > 0){
newImage = animate.animateCircle(animate.image, type);
g.drawImage(newImage, 400, 350, this);
}
すぐに役立つように、[SSCCE](http://sscce.org/)を投稿してください。 –