File: JiuHelloWorld.java

package info (click to toggle)
java-imaging-utilities 0.14.3-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,556 kB
  • sloc: java: 31,233; python: 71; xml: 31; makefile: 26; sh: 5
file content (47 lines) | stat: -rw-r--r-- 1,466 bytes parent folder | download | duplicates (5)
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
/*
 * JiuHelloWorld
 * 
 * Copyright (c) 2007 Marco Schmidt.
 * All rights reserved.
 */
package net.sourceforge.jiu.apps;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import net.sourceforge.jiu.codecs.CodecMode;
import net.sourceforge.jiu.codecs.PNGCodec;
import net.sourceforge.jiu.data.RGB24Image;
import net.sourceforge.jiu.gui.awt.ImageCreator;

/**
 * Small example command line program which creates a new image,
 * prints the text <em>Hello World!</em> into it and saves it as
 * a PNG file.
 * @author Marco Schmidt
 * @since 0.14.2
 */
public class JiuHelloWorld
{
	public static void main(String[] args) throws Exception
	{
		// AWT image creation
		BufferedImage awtImage = new BufferedImage(100, 30, BufferedImage.TYPE_INT_RGB);
		Graphics graphics = awtImage.getGraphics();
		// fill image with red
		graphics.setColor(Color.RED);
		graphics.fillRect(0, 0, awtImage.getWidth(), awtImage.getHeight());
		// draw on it in white
		graphics.setColor(Color.WHITE);
		graphics.drawString("Hello World!", 5, 15);
		// conversion AWT image to JIU image
		RGB24Image jiuImage = ImageCreator.convertImageToRGB24Image(awtImage);
		// saving JIU image to file
		PNGCodec codec = new PNGCodec();
		codec.setImage(jiuImage);
		codec.appendComment("Hello World! as a text comment; " + 
			"see http://schmidt.devlib.org/jiu/introduction.html");
		codec.setFile("jiu-hello-world.png", CodecMode.SAVE);
		codec.process();
	}
}