• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:TexturePaintを使って背景に画像を表示
#navi(../)
#tags()
#tags(TexturePaint, BufferedImage, Graphics2D)
RIGHT:Posted by &author(aterai); at 2004-09-20
*TexturePaintを使って背景に画像を表示 [#vf616c16]
TexturePaintを使用して背景にタイル状に画像を貼り付けます。
* TexturePaintを使って背景に画像を表示 [#vf616c16]
``TexturePaint``を使用して背景にタイル状に画像を貼り付けます。

-&jnlp;
-&jar;
-&zip;
- &jnlp;
- &jar;
- &zip;

//#screenshot
#ref(http://lh4.ggpht.com/_9Z4BYR88imo/TQTVUeXC5lI/AAAAAAAAAnc/CWUYfOODy1E/s800/TexturePaint.png)
#ref(https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTVUeXC5lI/AAAAAAAAAnc/CWUYfOODy1E/s800/TexturePaint.png)

**サンプルコード [#u3a94734]
** サンプルコード [#u3a94734]
#code(link){{
BufferedImage bi = null;
try {
  bi = ImageIO.read(getClass().getResource("16x16.png"));
}catch(IOException ioe) {
  ioe.printStackTrace();
}
texture = new TexturePaint(img, new Rectangle(bi.getWidth(), bi.getHeight()));
panel = new JPanel() {
  @Override public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D)g;
    g2.setPaint(texture);
    g2.fillRect(0, 0, getWidth(), getHeight());
    super.paintComponent(g);
  }
}
}}

**解説 [#j85ba7cb]
このサンプルでは、BufferedImageからTexturePaintを生成し、これをGraphics2D#setPaintメソッドで設定してパネル全体を塗りつぶしています。
** 解説 [#j85ba7cb]
このサンプルでは、``BufferedImage``から``TexturePaint``を生成し、これを``Graphics2D#setPaint``メソッドで設定してパネル全体を塗りつぶしています。

**参考リンク [#nc4c81eb]
-[[JPanelの背景に画像を並べる>Swing/BackgroundImage]]
** 参考リンク [#nc4c81eb]
- [[JPanelの背景に画像を並べる>Swing/BackgroundImage]]

**コメント [#e3931dfe]
** コメント [#e3931dfe]
#comment