Switch to full style
General Java code examples
Post a reply

Image Files Generation

Tue Nov 11, 2008 8:00 pm

Image Files Generation in java
Code:
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import javax.imageio.ImageIO;

public class GenerateImageType {
  static public void main(String args[]) throws Exception {
      int width = 200, height = 180;
      BufferedImage bufferedImage = new BufferedImage(width, height,
               BufferedImage.TYPE_INT_ARGB);
      Graphics2D g2d = bufferedImage.createGraphics();
    
    Font font 
= new Font("Arial", Font.BOLD, 24);
      g2d.setFont(font);
      String text = "Welcome!";
      FontMetrics fontMetrics = g2d.getFontMetrics();
      int stringWidth = fontMetrics.stringWidth(text);
      int stringHeight = fontMetrics.getAscent();
      g2d.setPaint(Color.black);
      g2d.drawString(text, (width - stringWidth) / 2, height / 2 + 
              stringHeight 
/ 4);
      
    ImageIO
.write(bufferedImage, "gif", new File("C:\\image.GIF"));
      ImageIO.write(bufferedImage, "JPEG", new File("C:\\image.JPG"));
      ImageIO.write(bufferedImage, "PNG", new File("C:\\image.PNG"));
      ImageIO.write(bufferedImage, "BMP", new File("C:\\image.BMP"));
      ImageIO.write(bufferedImage, "TIF", new File("C:\\image.TIF"));
   }
}
 




Post a reply
  Related Posts  to : Image Files Generation
 About Report Generation     -  
 dynamic crystal report generation     -  
 Basic daynamic page generation using CGIs programs     -  
 Image-Viewer-Image Processing-Filters-Noise-enhancements     -  
 Move image in front of a background image     -  
 different between cfa image and gray level image     -  
 jar files commands     -  
 Long files name     -  
 Get all files in folder     -  
 moving files in php     -  

Topic Tags

Java Image