Paint — 색 패턴 생성 인터페이스

Paint — 색 패턴 생성 인터페이스

Paint 인터페이스는 Graphics2D 연산을 위해 색 패턴을 어떻게 생성할지 정의해요. Paint 인터페이스를 구현하는 클래스를 Graphics2D 컨텍스트에 추가하면, drawfill 메서드가 사용할 색 패턴을 정의해요.

출처: Java API Reference

본문

public interface Paint extends Transparency

Paint를 구현하는 클래스의 인스턴스는 읽기 전용이어야 해요. 그 이유는 Graphics2DsetPaint 메서드로 속성으로 설정하거나 Graphics2D 객체 자체를 복제할 때 이 객체들을 복제하지 않기 때문이에요.

주요 메서드

  • createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints) — 색 패턴을 생성하는 데 사용하는 PaintContext를 만들고 반환해요. 반환된 PaintContext는 칠하기나 그리기 연산에서 색을 계산할 때 사용돼요.

대표 구현

  • Color — 단색 채우기
  • GradientPaint — 선형 그라데이션
  • TexturePaint — 텍스처(이미지) 채우기
  • LinearGradientPaint / RadialGradientPaint — 다중 색 그라데이션
Graphics2D g2 = (Graphics2D) g;
g2.setPaint(new GradientPaint(0, 0, Color.RED, 100, 100, Color.BLUE));
g2.fill(rect);

더 알아보기