TITLE:Shapeの反転

Shapeの反転

Posted by terai at 2008-07-28
  • category: swing folder: HorizontalFlip title: Shapeの反転 tags: [Shape, Font, AffineTransform] author: aterai pubdate: 2008-07-28T12:01:57+09:00 description: AffineTransformで図形や画像を反転して表示します。 image: https://lh5.googleusercontent.com/_9Z4BYR88imo/TQTN731lMzI/AAAAAAAAAbk/Wc0qp3ocR88/s800/HorizontalFlip.png

概要

AffineTransformで図形や画像を反転して表示します。

概要

AffineTransform で図形や画像を反転します。
  • &jnlp;
  • &jar;
  • &zip;

#screenshot

サンプルコード

#spanend
#spandel
Font font = new Font("Monospace", Font.PLAIN, 200);
#spanend
#spanadd
* サンプルコード [#sourcecode]
#spanend
#spanadd
#code(link){{
#spanend
#spanadd
Font font = new Font(Font.MONOSPACED, Font.PLAIN, 200);
#spanend
FontRenderContext frc = new FontRenderContext(null, true, true);
Shape copyright = new TextLayout("\u00a9", font, frc).getOutline(null);
#spandel
AffineTransform at = AffineTransform.getScaleInstance(-1.0, 1.0);
#spanend
#spandel
//at.translate(-copyright.getBounds().getWidth(), 0);
#spanend
#spandel
//AffineTransform at = new AffineTransform(-1d,0,0,1d,-copyright.getBounds().getWidth(),0);
#spanend
#spandel
//AffineTransform at = new AffineTransform(-1d,0,0,1d,0,0);
#spanend
#spanadd
AffineTransform at = AffineTransform.getScaleInstance(-1d, 1d);
#spanend
#spanadd
// Rectangle r = copyright.getBounds();
#spanend
#spanadd
// at.translate(r.getWidth(), r.getHeight());
#spanend
#spanadd
// AffineTransform at = new AffineTransform(
#spanend
#spanadd
//    -1d, 0d, 0d, 1d, r.getWidth(), r.getHeight());
#spanend
Shape copyleft = at.createTransformedShape(copyright);

解説

上記のサンプルでは、コピーライトの文字を鏡像反転して、コピーレフトのアイコン*1を作成しています。

解説

上記のサンプルでは、コピーライトの文字を鏡像(左右)反転してコピーレフトの文字アイコンを作成しています。

コメント

  • 上下反転の場合はAffineTransform.getScaleInstance(1d, -1d)が使用可能

参考リンク

コメント