public class ImageThumbnail
{
 private Image createThumbnail(Image image, int _thumbWidth, int _thumbHeight) {
  int sourceWidth = image.getWidth();
  int sourceHeight = image.getHeight();

  int thumbWidth = _thumbWidth;
  int thumbHeight = _thumbHeight;

  Image thumb = Image.createImage(thumbWidth, thumbHeight);
  Graphics g = thumb.getGraphics();

  for (int y = 0; y < thumbHeight; y++) {
   for (int x = 0; x < thumbWidth; x++) {
    g.setClip(x, y, 1, 1);
    int dx = x * sourceWidth / thumbWidth;
    int dy = y * sourceHeight / thumbHeight;
    g.drawImage(image, x - dx, y - dy,
    Graphics.LEFT | Graphics.TOP);
   }
  }

  Image immutableThumb = Image.createImage(thumb);

  return immutableThumb;
 }
}

Posted by Duritz

공지사항

Yesterday
Today
Total
02-19 11:01

달력

 « |  » 2025.2
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28