Java Foundation AWT generates a rectangular picture and writes the string inward

Source: Internet
Author: User

Li Wu:
Learn to think more, honouring teachers save Thanksgiving. Leaf See Root 321, rivers with one.
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 Jizuiku.image;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;/** * AWT generates a rectangular picture and writes the string inward * * @author to the bitter * @version V17.10.18 */public C Lass Createimagedemo {public static void main (string[] args) throws FileNotFoundException, IOException {//Get picture buffer int Widt H = 100;int height = 50;int ImageType = 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 of pen.fillrect (0, 0, 100, 50);//Microsoft JAS Black Bold display size 1 2Font font = new Font ("Microsoft Jas Black", Font.Bold);p en.setfont (font);//The Color of the word and background of the color to be different//to the most bitter for the first time did not notice, the results ran three or four times found no word ah pen.s Etcolor (Color.Blue);//write Pen.drawstring ("ABCD", ",") Imageio.write (MyImage, "JPEG", New FileOutputStream ("e:\\ A.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.

Java Foundation AWT generates a rectangular picture and writes the string inward

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.