The Artima Developer Community
Sponsored Link

Java Answers Forum
Save text file with images

5 replies on 1 page. Most recent reply: Sep 19, 2005 4:00 AM by Collin Garymore

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 5 replies on 1 page
Collin Garymore

Posts: 22
Nickname: callan
Registered: Jan, 2005

Save text file with images Posted: Sep 3, 2005 6:06 AM
Reply to this message Reply
Advertisement
Hi all,
I've got a problem and would like to know, if someone can give me an idea to deal with.
I'm utilising JTextPane to manipulate:
- Text and,
- Images.

I would like to save all together utilising JFileChooser option SaveOption.
Hum... It does not work-save.
Could someone give me some idea of which class to utilise for solving this problem.
Many thanks All.


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Save text file with images Posted: Sep 6, 2005 12:03 AM
Reply to this message Reply
Convert image to JPEG, then Google Advanced Imaging Image
API, you should have methods to write this format
to a local file system.

Amol Brid

Posts: 43
Nickname: amolbrid
Registered: Feb, 2004

Re: Save text file with images Posted: Sep 6, 2005 3:49 AM
Reply to this message Reply
This can be done writing the bytes of the string and image to a file.
First write the string length and string in a file. and then write the bytes of the image. You can use String.getBytes() to get string in bytes. For image you can use FileImageInputStream class.

The file format:
1-4 bytes - String length
5-string length - String
strng length+1 to EOF - image data.


Regards,
Amol

Collin Garymore

Posts: 22
Nickname: callan
Registered: Jan, 2005

Re: Save text file with images Posted: Sep 19, 2005 2:48 AM
Reply to this message Reply
Could someone, gives to me a example of this problems, please, I've been trying Filewriter, ImageIO, etc.
Nothing...


Please could someone do that for me then, an example.

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Save text file with images Posted: Sep 19, 2005 3:52 AM
Reply to this message Reply
> Could someone, gives to me a example of this
> problems, please, I've been trying Filewriter, ImageIO,
> etc.

/*  When you call this method: "someMethod" you should pass
 *  in a JPanel that has the pic that you want.
 */
public void someMethod(Component component){
   File file = new File("saveToThisFile.jpg");
   BufferedImage image = generatedBufferedImage(component);
   ImageIO.write(image, "jpg", file);
}
 
public BufferedImage generatedBufferedImage(Component component){
   BufferedImage image = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_RGB);
   Graphics g = image.getGraphics();
   g.fillRect(0, 0, image.getWidth(), image.getHeight());
   component.print(g);
   g.dispose();
   return image;
}


Good luck...

Collin Garymore

Posts: 22
Nickname: callan
Registered: Jan, 2005

Re: Save text file with images Posted: Sep 19, 2005 4:00 AM
Reply to this message Reply
Kondwani,
Many thanks for your time and the prompt of your answer.
I'll try this method today, and will let you know about the result thus,
Once more many thanks.

Flat View: This topic has 5 replies on 1 page
Topic: when to use ejbs Previous Topic   Next Topic Topic: Java problem in a card game

Sponsored Links



Google
  Web Artima.com   

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