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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
public void setImage(BufferedImage display) {
image = display;
Dimension size = new Dimension((int) (image.getWidth() * DISP_SCALE),
(int) (image.getHeight() * DISP_SCALE));
AffineTransform scale
= AffineTransform.getScaleInstance(1 / SCALE, 1 / SCALE);
AffineTransformOp op
= new AffineTransformOp(scale, AffineTransformOp.TYPE_BICUBIC);
image = op.filter(image, null);
setPreferredSize(size);
setMinimumSize(size);
}
@Override
public void paintComponent(Graphics graphics) {
Graphics2D g = (Graphics2D) graphics;
g.setColor(Color.WHITE);
g.fillRect(0, 0, getWidth(), getHeight());
/* Adjust the display. */
g.scale(getWidth() / (2.0 * image.getWidth()),
getHeight() / (2.0 * image.getHeight()));
g.translate(1.0, 1.0);
/* Tune drawing parameters. */
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
RenderingHints.VALUE_STROKE_PURE);
g.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
/* Draw image. */
g.setColor(Color.BLACK);
for (int y = 0; y < image.getHeight(); y++) {
for (int x = 0; x < image.getWidth(); x++) {
int c = image.getRGB(x, y);
/* Use the luma model. */
double sum = (+ 0.30 * (c >> 16 & 0xff)
+ 0.59 * (c >> 8 & 0xff)
+ 0.11 * (c >> 0 & 0xff)) / 255.0;
sum = 1.0 - sum;
double size = sum * SQ2;
g.fill(new Ellipse2D.Double((double) x * 2 - size,
(double) y * 2 - size,
size * 2, size * 2));
}
} |
Partager