File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Getting Bitmap from Canvas and converting it into image file format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Getting Bitmap from Canvas and converting it into image file format" Watch "Getting Bitmap from Canvas and converting it into image file format" New topic
Author

Getting Bitmap from Canvas and converting it into image file format

Nilesh Soni
Greenhorn

Joined: May 14, 2001
Posts: 21
Hi all,
I am drawing some lines or any shapes in an applet. now i want to save that drawing or applet into an image like gif or jpeg. one funda is that we will click on one button on applet, it will contact a setvlet on the server and on the server i have to write some code.
I got reply from one of the javaranch member Tim Holloway as follows:
You'll need to convert the applet's canvas into a bitmap, convert the bitmap into JPEG or GIF format, then send the bitmap in a binary file transmission to the server. The server really can't do anything but catch the file - all the work has to be done on the client.
Can any one help me out in this regards.
------------------
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Someone posted this code a while back... it draws some text on a canvas and saves it as a JPEG image... it helped me understand what to do to generate an image file from an image...



It saves it as a JPEG because a JPEG encoder is shipped with the JDK by Sun... to save as a GIF file you'll either need to look at the Java Media Framework, or go with a 3rd party implementation...

-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
GeeCON Prague 2014
 
subject: Getting Bitmap from Canvas and converting it into image file format