- JDK :OpenJDK-11
- OS :CentOS 7.6.1810
- IDE :Eclipse 2019‑03
- typesetting :Markdown
code
package per.jizuiku.gui;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
/**
* @author 給最苦
* @date 2019/06/30
* @blog www.cnblogs.com/jizuiku
*/
public class Demo {
/**
*
* @param args
* @throws FileNotFoundException
* @throws IOException
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
// 得到圖片緩沖區
int width = 100;
int height = 50;
int imageType = BufferedImage.TYPE_INT_BGR;
BufferedImage myImage = new BufferedImage(width, height, imageType);
// 得到畫筆
Graphics2D pen = (Graphics2D)myImage.getGraphics();
// 設置筆的顏色,即背景色
pen.setColor(Color.WHITE);
// 畫出一個矩形
// 坐標x 坐標y 寬度100 長度50
pen.fillRect(0, 0, 100, 50);
// monospace 粗體顯示 大小12
Font font = new Font("monospace", Font.BOLD, 25);
pen.setFont(font);
// 字的顏色 和 背景的顏色 要不同的
pen.setColor(Color.blue);
// 寫字
pen.drawString("abcd", 20, 35);
ImageIO.write(myImage, "JPEG", new FileOutputStream("abcd.jpg"));
}
}
result

sourceCode
/**
* Renders the text of the specified {@code String}, using the
* current text attribute state in the {@code Graphics2D} context.
* The baseline of the
* first character is at position (<i>x</i>, <i>y</i>) in
* the User Space.
* The rendering attributes applied include the {@code Clip},
* {@code Transform}, {@code Paint}, {@code Font} and
* {@code Composite} attributes. For characters in script
* systems such as Hebrew and Arabic, the glyphs can be rendered from
* right to left, in which case the coordinate supplied is the
* location of the leftmost character on the baseline.
* @param str the string to be rendered
* @param x the x coordinate of the location where the
* {@code String} should be rendered
* @param y the y coordinate of the location where the
* {@code String} should be rendered
* @throws NullPointerException if {@code str} is
* {@code null}
* @see java.awt.Graphics#drawBytes
* @see java.awt.Graphics#drawChars
* @since 1.0
*/
public abstract void drawString(String str, int x, int y);
resource
- [ JDK ] openjdk.java.net
- [ doc - 參考 ] docs.oracle.com/en/java/javase/11
- [ 規范 - 推薦 ] yq.aliyun.com/articles/69327
- [ 規范 - 推薦 ] google.github.io/styleguide
- [ 源碼 ] hg.openjdk.java.net
- [ OS ] www.centos.org
- [ IDE ] www.eclipse.org/downloads/packages
- [ 平台 ] www.cnblogs.com
感謝幫助過 給最苦 的人們。
Java、Groovy和Scala等基於JVM的語言,優秀,值得學習。
規范的命名和代碼格式等,有助於溝通和理解。
JVM的配置、監控與優化,比較實用,值得學習。
