Created
January 27, 2014 11:31
-
-
Save madan712/8646997 to your computer and use it in GitHub Desktop.
Java program to create an Icons of A-Z
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.awt.Color; | |
| import java.awt.Font; | |
| import java.awt.Graphics2D; | |
| import java.awt.image.BufferedImage; | |
| import java.io.File; | |
| import java.io.IOException; | |
| import javax.imageio.ImageIO; | |
| public class IconsAZ { | |
| public static void main(String[] args) { | |
| int width = 100; | |
| int height = 100; | |
| for (Character alphabet = 'A'; alphabet <= 'Z'; alphabet++) { | |
| //create a BufferedImage for mentioned image types. | |
| BufferedImage buffImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); | |
| //create a graphics2d object which can be used to draw into the buffered image | |
| Graphics2D g2d = buffImg.createGraphics(); | |
| //fill the rectangle with grey color | |
| g2d.setColor(Color.GRAY); | |
| g2d.fillRect(0, 0, width, height); | |
| //draw a string | |
| g2d.setColor(Color.yellow); | |
| g2d.setFont(new Font("TimesRoman", Font.BOLD, 100)); | |
| g2d.drawString(alphabet.toString(), 15, 80); | |
| //disposes of this graphics context and releases any system resources that it is using | |
| g2d.dispose(); | |
| //write the image file | |
| File f = new File("C:/Temp/"+alphabet+".jpg"); | |
| try { | |
| ImageIO.write(buffImg, "jpg", f); | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| System.out.println("Images created successfully!"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment