saving an image to file (with other contents...)

T

tiewknvc9

Hi!

Im having trouble finding a resource that discusses this topic, so I
figured I would make a post here.

I have a little program where the user can enter text and select
graphics to show within the program. I offer the ability to save
their creations... BUT since I store the graphics that they have
selected as the path to the graphic... if they want to share their
creations with their friends the graphics do not show up because their
friends dont have the graphics!

SO my question is, is there a way to embed the graphics into the save
file? How can I do this? Then how would I grab the file from the
save file when their friends open the file? Is there an example
somewhere online?

Thanks!
 
K

Knute Johnson

tiewknvc9 said:
Hi!

Im having trouble finding a resource that discusses this topic, so I
figured I would make a post here.

I have a little program where the user can enter text and select
graphics to show within the program. I offer the ability to save
their creations... BUT since I store the graphics that they have
selected as the path to the graphic... if they want to share their
creations with their friends the graphics do not show up because their
friends dont have the graphics!

SO my question is, is there a way to embed the graphics into the save
file? How can I do this? Then how would I grab the file from the
save file when their friends open the file? Is there an example
somewhere online?

Thanks!

It is really not clear what you are asking as can be seen from the lack
of response to your post.

Do you want to save an image to a file?
|
|
|
Yes ------------------ No
| |
| |
ImageIO |
|
|
Is it really a just drawing and not an image?
|
|
|
Yes --------------------------------- No
| |
| |
Then you are going to have to Then what the heck
create an image because you is it?
can't just save your drawing.
(See the answer above)
 
T

tiewknvc9

ok - to clarify...

What I would like to save is a set of data. so for instance, a text
field, and an image. I want to combine these items into a single save
file. The text (entirely seperate from the image) should be saved to
file, along with the image.

When the user opens the file that was saved (a single file containing
the text, and the image) it will open the file and insert the text
into a text box, and the image (if specified) into the image area...
 
K

Knute Johnson

tiewknvc9 said:
ok - to clarify...

What I would like to save is a set of data. so for instance, a text
field, and an image. I want to combine these items into a single save
file. The text (entirely seperate from the image) should be saved to
file, along with the image.

When the user opens the file that was saved (a single file containing
the text, and the image) it will open the file and insert the text
into a text box, and the image (if specified) into the image area...

OK that makes a lot more sense. Many objects can be serialized and
saved to disk. Although the Image class can't be serialized, the
BufferedImage can have its data saved in an array and an array can be
serialized. A JTextField keeps its data in a String which can also be
serialized. So you could create a class that held your String and your
array and write that to disk. If they don't have to be in the same
exact file your could easily write the image to one file and the string
data to the other. The only drawback is two files but the advantages
are obvious.
 
R

Roedy Green

SO my question is, is there a way to embed the graphics into the save
file? How can I do this? Then how would I grab the file from the
save file when their friends open the file? Is there an example
somewhere online?

With HTML you never embed the file. You save the image an a separate
file, and embed a link to it in the HTML. see
http://mindprod.com/jgloss/pngencoder.html for how you create image
files.

If you create your own file format, you can embed images. You might
do it with a length followed by the binary image, identical to what it
would be as a standalone file. You might then compress the whole
thing, or compress the embedded images.
 
T

tiewknvc9

thanks for the feedback, but I am working with an application. The
HTML does not apply...
 
T

tiewknvc9

OK that makes a lot more sense. Many objects can be serialized and
saved to disk. Although the Image class can't be serialized, the
BufferedImage can have its data saved in an array and an array can be
serialized. A JTextField keeps its data in a String which can also be
serialized. So you could create a class that held your String and your
array and write that to disk. If they don't have to be in the same
exact file your could easily write the image to one file and the string
data to the other. The only drawback is two files but the advantages
are obvious.


thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top