Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2007

Tip: Looking for answers? Try searching our database.

Saving canvas

Thread view: 
exylum - 29 Jul 2007 15:59 GMT
Hi. I have a problem with saving canvas to file. All over net there
are faqs on how to save a NEW canvas to file (after drawing on it). I
have a canvas, what should i do in order to save what's currently on
it to a file?
Knute Johnson - 29 Jul 2007 18:24 GMT
> Hi. I have a problem with saving canvas to file. All over net there
> are faqs on how to save a NEW canvas to file (after drawing on it). I
> have a canvas, what should i do in order to save what's currently on
> it to a file?

Do you want to save a canvas or some sort of image to the file?  Canvas
is Serializable so you can write it to a file using ObjectOutputStream.
 That may or may not allow you to recreate what was drawn on the
Canvas.  If what you want is an image saved to a file, you should draw
on a BufferedImage and save that to the file using ImageIO.  You can
display the BufferedImage on your Canvas.

Signature

Knute Johnson
email s/nospam/knute/

exylum - 29 Jul 2007 19:21 GMT
On 29 Lip, 19:24, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
wrote:
> > Hi. I have a problem with saving canvas to file. All over net there
> > are faqs on how to save a NEW canvas to file (after drawing on it). I
[quoted text clipped - 12 lines]
> Knute Johnson
> email s/nospam/knute/

I've noticed a lot of examples in the web on how to save bufferedimage
to file, which, in answer to Your question, is my goal. I just wanted
to find out if there is any way of saving the image directly from
canvas. Thank You for Your answer.
Roedy Green - 29 Jul 2007 19:45 GMT
>I've noticed a lot of examples in the web on how to save bufferedimage
>to file, which, in answer to Your question, is my goal. I just wanted
>to find out if there is any way of saving the image directly from
>canvas. Thank You for Your answer.
You could screen scrape to capture the bits on the screen.
See http://mindprod.com/jgloss/screenscraping.html
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Knute Johnson - 29 Jul 2007 19:52 GMT
> On 29 Lip, 19:24, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
> wrote:
[quoted text clipped - 18 lines]
> to find out if there is any way of saving the image directly from
> canvas. Thank You for Your answer.

If the only drawing on your Canvas is done in the paint() method you
could use that method to draw onto the BufferedImage.  The technique
would be to get a draw Graphics for the BufferedImage and then call
paint() with that Graphics.  If your drawing is going to be from user
interaction then using the BufferedImage as your drawing surface and
displaying that to the user makes more sense.  Of course in the first
case above, serializing the Canvas would work too.

Signature

Knute Johnson
email s/nospam/knute/

Roedy Green - 30 Jul 2007 11:33 GMT
>Of course in the first
>case above, serializing the Canvas would work too.
I suspect that a serialised Canvas could not be reconstituted in a
different machine. I think it will be specific to the screen hardware.
I know Image has this problem.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Knute Johnson - 30 Jul 2007 18:01 GMT
>> Of course in the first
>> case above, serializing the Canvas would work too.
> I suspect that a serialised Canvas could not be reconstituted in a
> different machine. I think it will be specific to the screen hardware.
> I know Image has this problem.

In a serialized object all that gets stored are the fields.  The data to
recreate the drawing would have to be stored in fields in the Canvas.
The actual drawing surface would be lost.  I need to play with this some
but I've got to go to work this week.  If I have time I'll post
something from the road :-).  Interesting possibilities though.

Signature

Knute Johnson
email s/nospam/knute/

Roedy Green - 29 Jul 2007 19:43 GMT
>Hi. I have a problem with saving canvas to file. All over net there
>are faqs on how to save a NEW canvas to file (after drawing on it). I
>have a canvas, what should i do in order to save what's currently on
>it to a file?
see http://mindprod.com/jgloss/jpegencoder.html
http://mindprod.com/jgloss/pngencoder.html
http://mindprod.com/jgloss/gifencoder.html
Also just save the data you used to generate the image using a
DataOutputStream of ObjectOutputStream. See
http://mindprod.com/applet/fileio.html for sample code.
For complete sample code that does this see
http://mindprod.com/products.html#MASKER

You will don't literally save the bits being viewed on a Canvas --
it's bits are in proprietary video-card format in the hardware REGEN
buffer.  You repaint the Canvas with a different sort of Graphics
object that saves the bits in a more standard format to ordinary RAM.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.