The Artima Developer Community
Sponsored Link

Java Answers Forum
displaying text in jpeg image

1 reply on 1 page. Most recent reply: Mar 20, 2002 2:45 PM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
jayakumar perumal

Posts: 16
Nickname: jai
Registered: Feb, 2002

displaying text in jpeg image Posted: Mar 18, 2002 1:28 PM
Reply to this message Reply
Advertisement
can anyone help me to know how to display text in jpeg image.
thanx
jai


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: displaying text in jpeg image Posted: Mar 20, 2002 2:45 PM
Reply to this message Reply
The following code creates a jpeg image file file and writes text into it. You could adapt it to your problem or program.

/** CreateJPEG.java
* @author Charles Bell
* @version December 12, 2000
*/

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

public class CreateJPEG{


public static void main(String[] args){
CreateJPEG createjpeg = new CreateJPEG();
createjpeg.init();
}

public void init(){
try{
String filename = "MyJPEG.jpg";
int imagewidth = 200;
int imageheight = 25;
int imageType = BufferedImage.TYPE_INT_RGB;
// Create an image buffer in which to paint on.
BufferedImage jpegimage = new BufferedImage(imagewidth, imageheight,imageType);

// Create graphics object associated with the jpeg image
Graphics2D graphics2d = jpegimage.createGraphics();

// Paint image on the graphics object
graphics2d.setColor(Color.black);
graphics2d.drawRect(1,1,imagewidth,imageheight);
graphics2d.setColor(Color.red);
graphics2d.drawString("My JPEG",1,10);
//graphics2d.dispose();

// JPEG-encode the image
//and write to file.
OutputStream os = new FileOutputStream(filename);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os);
encoder.encode(jpegimage);
os.close();
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}

}

}

Flat View: This topic has 1 reply on 1 page
Topic: about the credit score decision engine in java Previous Topic   Next Topic Topic: slow painting while reading and writing doubles for MB Files

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use