• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Text to Image to File

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry guys if I am posting it in the wrong forum.
I am trying to convert a text value (String) to an image (.jpg). My program seems to be working somewhat. It's creating a blank (whiite background) .jpg file, without my string value "Saidul Islam". I can open the file in any image editor. it just doesn't have the string I am trying to print.
And the strange part is that the program is not even terminating.
Here is the output I get when I run it
<pre>
C:\test>java Text2Image
gets here
flushed
closed
final
dispose
remove notify
done!
</pre>
it's of course printing the last line but the program is not terminating. I have been working on this since yesterday. and my brain is not functioning anymore on this. So I ask for your help.
what am I doing wrong and how do I get this working.
Here is my program-
<pre>
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import com.sun.image.codec.jpeg.*;

public class Text2Image {
public static void main(String args[]) {
Frame myFrame = null;
Graphics2D myGraphics = null;
try {
myFrame = new Frame();
myFrame.addNotify();
BufferedImage buffImage = new BufferedImage(400, 200, BufferedImage.TYPE_INT_RGB);
BufferedImage buff2Image = new BufferedImage(400, 200, BufferedImage.TYPE_INT_RGB);
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("text.jpg"));
Image offImage = myFrame.createImage(400, 200);
//myGraphics = buffImage.getGraphics();
myGraphics = buffImage.createGraphics();
myGraphics.setFont(new Font("Serif", Font.ITALIC, 48));
myGraphics.setColor(Color.red);
myGraphics.drawString("Saidul Islam", 10, 50);
myGraphics.drawImage(offImage, 0, 0, myFrame);
buffImage.createGraphics().drawImage(buffImage, 0, 0, myFrame);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
encoder.encode(buffImage);

//JpegEncoder jpg = new JpegEncoder(offImage, 80, bos);
//jpg.Compress();

System.out.println("gets here");
bos.flush();
System.out.println("flushed");
bos.close();
System.out.println("closed");

buffImage.flush();
buff2Image.flush();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
System.out.println("final");
if (myGraphics != null) {
myGraphics.dispose();
System.out.println("dispose");
}
if (myFrame != null) {
myFrame.removeNotify();
System.out.println("remove notify");
}
}
System.out.println("done!");
} //end of main method
} //end of Text2Image class
</pre>

Thanks for your help!
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I answered your question in the JFC/Swing/AWT forum... please do not cross-post questions to several forums.

-Nate
[This message has been edited by Nathan Pruett (edited May 31, 2001).]
 
Drove my Chevy to the levee but the levee was dry. A wrung this tiny ad and it was still dry.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic