- JDK :OpenJDK-11
- OS :CentOS 7.6.1810
- IDE :Eclipse 2019‑03
- typesetting :Markdown
package per.jizuiku.gui; import java.awt.BasicStroke; import java.awt.Color; 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 */ public static void main(String[] args) { try { getImage(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * * @throws FileNotFoundException * @throws IOException */ public static void getImage() 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); // 字的顏色 和 背景的顏色 要不一樣的 pen.setColor(Color.blue); // 劃線 // 點動成線,線動成面,面動成體 // 兩點肯定一條直線 int xStart = 5; int yStart = 15; int xEnd = 60; int yEnd = 30; // 設置線的寬度 float lineWidth = 7F; pen.setStroke(new BasicStroke(lineWidth)); pen.drawLine(xStart, yStart, xEnd, yEnd); ImageIO.write(myImage, "JPEG", new FileOutputStream("line" + ".jpg")); } }
/** * Draws a line, using the current color, between the points * <code>(x1, y1)</code> and <code>(x2, y2)</code> * in this graphics context's coordinate system. * @param x1 the first point's <i>x</i> coordinate. * @param y1 the first point's <i>y</i> coordinate. * @param x2 the second point's <i>x</i> coordinate. * @param y2 the second point's <i>y</i> coordinate. */ public abstract void drawLine(int x1, int y1, int x2, int y2);
感謝幫助過 給最苦 的人們。
Java、Groovy和Scala等基於JVM的語言,優秀,值得學習。
規範的命名和代碼格式等,有助於溝通和理解。
JVM的配置、監控與優化,比較實用,值得學習。java