Javase base AWT graphics2d Create a rectangular picture and draw a line to it

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.