ImageGraphicAttribute 클래스

ImageGraphicAttribute 클래스

ImageGraphicAttribute 클래스는 TextLayout에서 이미지를 그리는 GraphicAttribute의 구현이에요. 텍스트 흐름 안에 이미지를 내장할 때 사용해요.

출처: Java API Reference

본문

이 클래스는 GraphicAttribute를 상속해요. GraphicAttribute의 추상 메서드인 draw, getAdvance, getAscent, getDescent를 이미지 렌더링에 맞게 구현해요.

public final class ImageGraphicAttribute
extends GraphicAttribute

생성자

  • ImageGraphicAttribute(Image image, int alignment) — 지정한 이미지와 정렬로 인스턴스를 만들어요.
  • ImageGraphicAttribute(Image image, int alignment, float originX, float originY) — 이미지 내부의 원점을 지정해서 만들어요. originX와 originY는 이미지의 왼쪽 상단에 상대적인 위치예요.

사용 목적

텍스트 레이아웃에서 아이콘이나 작은 그림을 문자처럼 배치하고 싶을 때 유용해요. 예를 들어 문서 내 인라인 이미지, 커스텀 이모지, 아이콘 등을 TextLayout 안에 자연스럽게 녹일 수 있어요.

GraphicAttribute의 다른 구현으로는 도형을 그리는 ShapeGraphicAttribute가 있어요. ImageGraphicAttribute는 이미지를, ShapeGraphicAttribute는 벡터 도형을 그린다는 차이가 있어요.

주의

ImageGraphicAttribute는 직렬화되지 않아요. FontCHAR_REPLACEMENT 속성으로 사용할 때 직렬화 문제에 주의해야 해요.

더 알아보기