标签:except es2017 stat col star imp throw 资源 cst
礼悟:
好好学习合思考,尊师重道存感恩。叶见寻根三返一,江河湖海同一体。
虚怀若谷良心主,愿行无悔给最苦。读书锻炼强身心,诚劝且行且珍惜。
os :windows7 x64
jdk:jdk-8u131-windows-x64
ide:Eclipse Oxygen Release (4.7.0)
代码
package com.jizuiku;
import java.awt.BasicStroke;
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 博客园-给最苦
* @version V2017.11.30
*/
public class DrawLineDemo {
public static void main(String[] args) {
try {
getImage();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
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("E:\\" + "line" + ".jpg"));
}
}
效果

Java优秀,值得学习。
学习资源:itcast和itheima视频库。如果您有公开的资源,可以分享给我的话,用您的资源学习也可以
博文是观看视频后,融入思考写成的。博文好,是老师讲得好。博文坏,是 给最苦 没认真。
JavaSE基础 awt Graphics2D 生成矩形图片并向其中画一条直线
标签:except es2017 stat col star imp throw 资源 cst
原文地址:http://www.cnblogs.com/jizuiku/p/7988083.html