Li Wu:
Good study and thinking, honouring teachers save Thanksgiving. Leaf See root three return to one, rivers the same oneness.
Meekness Conscience Lord, willing to do without regrets to the most bitter. Reading exercise strong body and mind, Prudential advised and the line and cherish.
Os:windows7 x64
Jdk:jdk-8u131-windows-x64
Ide:eclipse Oxygen Release (4.7.0)
Code
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 Blog Park-to the most bitter * @version V2 017.11.30 */public class Drawlinedemo {public static void main (string[] args) {try {getImage ()} catch (IOException e) {// TODO auto-generated catch Blocke.printstacktrace ();}} public static void GetImage () throws FileNotFoundException, IOException {//Get picture buffer int width = 100;int height = 50;int ima Getype = BUFFEREDIMAGE.TYPE_INT_BGR; BufferedImage myimage = new BufferedImage (width, height, imageType);//Get brush graphics2d pen = (graphics2d) myimage.getgraph ICS ();//Set the color of the pen, that is, the background color pen.setcolor (color.white);//Draw a rectangle//coordinate x coordinate y width 100 length 50pen.fillrect (0, 0, 100, 50);//The color of the word or the color of the background or Pen.setcolor (Color.Blue);//dash//point-to-line, line-driven, face-motion adult//two-point to determine a straight line int xstart = 5;int Ystart = 15;int XEnd = 60;int yend = 30;//Set the width of the line float linewidth = 7f;pen.setstroke (new Basicstroke (linewidth));p en.drawline (Xstart, YStart, XEnd, yend); Imageio.write (MyImage, "JPEG", New FileOutputStream ("e:\\" + "line" + ". jpg"));}}
Effect
Java is good, worth learning.
Learning resources: Itcast and Itheima Video library. If you have public resources, can share to me, with your resources to learn can also
Blog post is to watch the video, into thinking written. It's good that the teacher speaks well. Blog bad, is to give the most bitter not serious.
Javase base AWT graphics2d Create a rectangular picture and draw a line to it