Java Graphics processing-java graphics2d

Source: Internet
Author: User

 PackageCom.mapbar.graphics;ImportJava.awt.Graphics2D;ImportJava.awt.geom.Ellipse2D;ImportJava.awt.geom.Line2D;ImportJava.awt.geom.Rectangle2D;ImportJava.awt.image.BufferedImage;ImportJava.io.File;Importjava.io.IOException;ImportJavax.imageio.ImageIO;/*** Class Drawgraphics.java * Description java2d draw line, rectangle, ellipse, rotate graphic * Company Mapbar * Author CHENLL * Version 1.0 * Date 2012-7-20 pm 12:06:15*/ Public classdrawgraphics{Privatebufferedimage image; Privategraphics2d Graphics;  Public voidinit () {intwidth=480,hight=720; Image=NewBufferedImage (WIDTH,HIGHT,BUFFEREDIMAGE.TYPE_INT_RGB); //Get the graphics contextGraphics =(graphics2d) image.getgraphics (); }            /*** Create a (X1,Y1) to (X2,Y2) line2d Object *@throwsIOException*/     Public voidDrawLine ()throwsioexception{init (); Line2D Line=NewLine2d.double (2,2,300,300);         Graphics.draw (line);         Graphics.dispose (); Outimage ("PNG", "D:\\line.png"); }            /*** Create an upper-left corner coordinate is (50,50), width is 300, height is 400 of a rectangle object *@throwsIOException*/     Public voidDrawRect ()throwsioexception{init (); Rectangle2D rect=NewRectangle2d.double (50,50,400,400);        Graphics.draw (rect);        Graphics.fill (rect);        Graphics.dispose (); Outimage ("PNG", "D:\\rect.png"); }        /*** created a top-left coordinate is (50,50), width is 300, height is 200 of an Ellipse object, if high, wide, it is a standard circle * *@throwsIOException*/     Public voidDrawEllipse ()throwsioexception{init (); Ellipse2d Ellipse=NewEllipse2d.double (50,50,300,200);        Graphics.draw (ellipse);        Graphics.fill (ellipse);        Graphics.dispose (); Outimage ("PNG", "D:\\ellipse." PNG "); }         /*** Output Drawn graphics *@paramtype *@paramFilePath *@throwsIOException*/     Public voidOutimage (String type,string FilePath)throwsioexception{imageio.write (Image,type,NewFile (FilePath)); }         Public Static voidMain (string[] args)throwsioexception{drawgraphics DG=NewDrawgraphics ();        Dg.drawline ();        Dg.drawrect ();    Dg.drawellipse (); }}

Java Graphics processing-java graphics2d

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.