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 / GUI / February 2005

Tip: Looking for answers? Try searching our database.

Java Canvas Object: how to redraw?

Thread view: 
Ed Dana - 27 Feb 2005 06:30 GMT
I have created a small paint program in order to become more familiar
with Java. I am using the Canvas object to draw on, but whenever the
window is covered, I loose my work.

How do I preserve this information for repainting. I've tried getting
the Image from the Canvas and then tried to paint it back later, but
nothing is working.

Any and all clues appreciated.

Ed.
Tjerk Wolterink - 27 Feb 2005 15:56 GMT
> I have created a small paint program in order to become more familiar
> with Java. I am using the Canvas object to draw on, but whenever the
[quoted text clipped - 7 lines]
>
> Ed.

You could create your own Image object,.. paint lines on that image, and then render that image
to the canvas.. A other solution.. but more complex .. is to create Objects that represent lines.. and a
Painting object.. And then call. Painting.drawMySoBeautifullPainting(Graphics g).. that is the vector approach
Ed Dana - 27 Feb 2005 17:05 GMT
> You could create your own Image object,.. paint lines on that image, and
> then render that image
> to the canvas..

Thanks, I just tried that, and it helped but the application is slower now.

Since it is faster to directly paint on the canvas, what I'd really like
to do is get the image from the canvas after the brush stroke completes,
both for repainting and a redo function. Everything I've tried there has
failed.

Does anyone have any ideas on how I can extract an image from a canvas?
Everything I've tried so far has failed.

Ed.
johndoe@example.com - 27 Feb 2005 18:09 GMT
>> You could create your own Image object,.. paint lines on that image, and
>> then render that image
[quoted text clipped - 9 lines]
> Does anyone have any ideas on how I can extract an image from a canvas?
> Everything I've tried so far has failed.

You can't.

The correct way to solve the problem (not only in Java, but in Win32,
MacOS X, X11, etc.) is to draw to a buffered image and blit that image
onto your canvas as required.
Ed Dana - 27 Feb 2005 19:25 GMT
> The correct way to solve the problem (not only in Java, but in Win32,
> MacOS X, X11, etc.) is to draw to a buffered image and blit that image
> onto your canvas as required.

Thanks, that helps, but... How do I "blit" it to the canvas?

Ed.
Ed Dana - 27 Feb 2005 19:52 GMT
>> The correct way to solve the problem (not only in Java, but in Win32,
>> MacOS X, X11, etc.) is to draw to a buffered image and blit that image
>> onto your canvas as required.
>
> Thanks, that helps, but... How do I "blit" it to the canvas?

By George, I think I've got it! :)

Rather than blitting, I'm drawing to the canvas first, and when the
stroke is completed, I draw to the Buffered Image. Seems to work so far.

Thanks all.

Ed.
johndoe@example.com - 28 Feb 2005 19:51 GMT
> Thanks, that helps, but... How do I "blit" it to the canvas?

Graphics.drawImage()


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



©2010 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.