Encode JPanel as Gif

i want to use ACME's GifEncoder to encode the JPanel as gif ...
for encoding Jpeg, i just printAll() the JPanel to form a BufferedImage for encoding ...
but the GifEncode need a Image object (not BufferedImage), so how could i create a BufferedImage from a JPanel ??
thx

Hi Yundi! :-)
One hand washes the other one, right?
I suppose you mean: How to create an Image from a JPanel and not a BuffedImage?
I do this like that (ok, bit of dirty way, but I have to scale my image):
BufferedImage bi;
Image img = bi.getScaledInstance( width, height, Image.SCALE_DEFAULT );

Similar Messages

  • How to decoding and encoding PNG and GIF images?

    I could decode and encode JPEG images using following create functions which are in com.sun.image.codec.jpeg package.
    JPEGImageDecoder decoder = JPEGCodec          .createJPEGDecoder(inputStream);
    JPEGImageEncoder encoder = JPEGCodec                    .createJPEGEncoder(outputStream);
    But I dont know required package and functions to decode and encode PNG and GIF images. Please help me.

    Is the API that hard to follow?
    ImageIO.read( file/stream/url)
    ImageIO.write( image, format (e.g. PNG, GIF(1), JPEG), file/stream what have you)
    1) Not sure if Java supports GIF saving, it might if you install JAI, or Java 6.

  • Java Swing - save JPanel as GIF/JPEG.

    WE are using Java swing to draw graph(Genes, SNP ,repeats etc related to bio-informatics).text files we are using are quite big eg- more than 25 MB. first it makes the process slow.One of our problem is to save whatever "we draw as an image file(GIF/JPEG file)" and another problem is save a data in a data structure(array,vector) which grow upto 15-20 MB.
    plotting this data makes the speed too slow.We want to optimize this.

    For saving images have a look at JAI - the Java Advanced Imaging API. It's got fairly straightforward ways of saving images. Note that saving as GIF images is not recommended; patents were placed on the encoding so it's no longer a free option. PNG will give you lossless compression like GIF but is more flexible.
    http://java.sun.com/products/java-media/jai/
    Saving the generated (mined?) data structure for future retrieval can be quite straightforward depending on how you're doing it. The easiest way is simply to serialise it (use an ObjectOutputStream) but this has compatibility problems if you change your data structure.
    Saving out in a custom format may seem like a lot of work but it's not all that hard to do. Alternatively you can use one of the Java to XML convertors - in your case this might generate too large a file, however.
    YOu can always use Java's zip functions to improve file size should this become problematic.
    Hope this helps

  • Loss transparency in an animated GIF image when resizing

    Hi Friends,
    I have to write a program to resize GIF, JPEG , and PNG images. I wrote and it works but when i resize a GIF file it loses its transparency and give a black color for transparent area.
    I used a GifDecoder found at www.fmsware.com/stuff/GifDecoder.java
    and a gif encoder found at jmge.net/java/gifenc/Gif89a090b.zip.
    i don't know where the problem is .
    i have some small problems in here.
    How can i preserve the transparency of GIF image?
    How can i set a transparent color in Graphic2D object? smtimes it may help me. or error may be in the encoder.
    Help me guys.
    Thanks and regards,
    Manjula

    Java comes with gif encoder/decoders.
    Gifs are indexed images. This means that, for example, each pixel is an 8 bit value that is used to look up the correct 24 bit value in the index table. Gifs handle transparency by allowing one particular pixel value to be nominated as transparent.
    If you just rescale the image then you will likely cause pixels with the magic "transparent" value to change their value and become normal pixels. Alternately pixels that are not transparent may have their values changed such that they are transparent.
    Possibly the easyist solution to to force the image into a full RGBA image. Scale this then perform post processing on the image. I.e convert it back into an indexed image, looking at the values of the alpha channel (prior to making it indexed and if they are high enough then modify the corresponding pixel in the indexed image to have the magic transparent value. Then use Metadata passed to your Image writer to indicate which value is transparent.
    matfud

  • Using JPanel in Forte

    Is there anyway to save drawings created in the JPanel as .jpeg file or .gif file and print it out? Or can we convert drawings/picture in JPanel into .gif /.jpeg? If can, how to do so?

    If you are willing to load the Java Advanced Imaging package from Sun, you can manipulate the files in just about any way you like and save them in just about any format. I use it with some JPG's and some TIFF's.

  • 2/3 Glaspanes over eachother, with a JPanel at the bottom.

    Hi all!
    I wonder if it is posible to have a JPanel (with gifs, jpgs etc) and two/three GlassPanes(with gifs, jpgs etc) over eachother for use i games etc.
    I have succeded of creating this with one window, but i have five or six windows but i only want the glaspane to effect one window, since i dont wanna lock all the windows.. is this possible at all with swing?
    Becouse everytime I add a glass pane to a window the things in it(behind the glaspane), disapear. Any ideas?
    Thanks in advance!
    //SAJBER

    { inside Container(C)
    Jpanel1(p1){ inside p1
    p1.add(RightWin);
    Jpanel2(p2){ inside p2
    (JScrollPanel) GameWin{inside GameWin
                                (JPanel)  GameBackground {inside GameBackground
                                      (JLabel)GameBackground.add(tile); (image)
                                      (GlassPanel)GB.add(layer1); (glasspane){inside   layer1                                    (GlassPanel)layer2 (draws a image an squares
                                                    (GlassPanel)layer3(draws rotating polygon)
    p2.add(ChatTabs);
    p2.add(ChatWin);
    p2.add(ChatBar);
    Jpanel 3(p3){ inside p3
    p3.add(LeftWin);
    p3.add(LeftWin2);
    problem is that I can only view eather the content of GameBackground, Layer1, layer 2 or layer3 at once. I would like to at least show the background who is a JPanel and at least one glas panel over it at the same time, but I cant!!
    I try to add use GameBackground.add(layer1), but if I do that the the old things added to GameBackground is over written. All the glass and JPanel are setOpaque(false).

  • Displaying a dynamic image in a jsp

    I am interested in the way of dynamically generating an image in a web browser. The image should be formed on the servlet, more precisely with the aid of a servlet, and reloaded in the web browser every time it suffers modifications (for example, elements are drawn). The drawing and displaying part is already functioning not as a server application, but as a desktop one. The result of the drawing actions are displayed in a Bufferd Image view. What I have to do is to display this image in the browser, encoded as a gif (I already know how to do the encoding part).
    //code from TheServlet.java
    ImageViewPort view = new ImageViewPort(600, 600); // BufferedImage type
    Image image = view;
    g = image.getGraphics();
    response.setContentType("image/gif");
    GifEncoder encoder = new GifEncoder(image, out);
    encoder.encode();
    How would I correctly reference in the HTML form this servlet? In the HTML form I have to display the dynamically created GIF image as a server side image map?
    // code from the HTML form
    <img WIDTH=600 HEIGHT=600 BORDER="2" src="http://localhost:8080/servlet/TheServlet");
    ISMAP/>
    How should be written the source of these image map?

    you can use AJAX for this.. google maps is using ajax for rendering their maps..

  • Multipart/related part specifiers

    Hi, this query is perhaps the result of my own limited knowledge regarding MIME types and part specifiers but here goes....
    Based on the following BODYSTRUCTURE, I am attempting to determine the associated part specifiers so I may get the MIME headers for said part (i.e. A12 UID FETCH 147859 (BODY.PEEK[1.MIME])).
    A11 UID FETCH 147859 (BODYSTRUCTURE)
    * 1 FETCH (BODYSTRUCTURE (("TEXT" "PLAIN" ("CHARSET" "US-ASCII") NIL NIL "QUOTED-PRINTABLE" 911 16 NIL NIL NIL)(("TEXT" "HTML" ("CHARSET" "US-ASCII") NIL NIL "QUOTED-PRINTABLE" 2716 46 NIL NIL NIL)("IMAGE" "BMP" ("name" "ExchangeBabs.bmp") "<297231021@11102006-1D66>" NIL "BASE64" 2634474 NIL ("inline" ("filename" "ExchangeBabs.bmp")) NIL)("APPLICATION" "OCTET-STREAM" ("name" "Presence_K1=XItJBkk1xQi8X5JIgeeyjkn9EJTYKfxg9AogMsw3qHMhNnawbZ5wVWrmDFYTq1yP&MODE=IMG") NIL NIL "BASE64" 732 NIL ("inline" ("filename" "Presence_K1=XItJBkk1xQi8X5JIgeeyjkn9EJTYKfxg9AogMsw3qHMhNnawbZ5wVWrmDFYTq1yP&MODE=IMG")) NIL)("IMAGE" "GIF" ("name" "Blank Bkgrd.gif") "<297231021@11102006-1D6D>" NIL "BASE64" 202 NIL ("inline" ("filename" "Blank Bkgrd.gif")) NIL) "related" ("boundary" "-------45363d5545363d55") NIL NIL) "alternative" ("boundary" "-------446e3c8d446e3c8d") NIL NIL) UID 147859)
    The com.sun.mail.imap.protocol.BODYSTRUCTURE object generated is shown below (I've omitted most of the fields and left what I considered relevent, simply enough to show the nesting):
    bs= BODYSTRUCTURE  (id=181)
         bodies= BODYSTRUCTURE[2]  (id=199)
              [0]= BODYSTRUCTURE  (id=207)
                   bodies= null
                   encoding= "QUOTED-PRINTABLE"
                   subtype= "PLAIN"
                   type= "TEXT"
              [1]= BODYSTRUCTURE  (id=208)
                   bodies= BODYSTRUCTURE[4]  (id=213)
                        [0]= BODYSTRUCTURE  (id=216)
                             bodies= null
                             encoding= "QUOTED-PRINTABLE"
                             subtype= "HTML"
                             type= "TEXT"
                        [1]= BODYSTRUCTURE  (id=217)
                             bodies= null
                             encoding= "BASE64"
                             subtype= "BMP"
                             type= "IMAGE"
                        [2]= BODYSTRUCTURE  (id=218)
                             bodies= null
                             encoding= "BASE64"
                             subtype= "OCTET-STREAM"
                             type= "APPLICATION"
                        [3]= BODYSTRUCTURE  (id=219)
                             bodies= null
                             encoding= "BASE64"
                             subtype= "GIF"
                             type= "IMAGE"
                   subtype= "related"
                   type= "multipart"
         subtype= "alternative"
         type= "multipart"This particular message has a multipart/related content-type:
    MIME-Version: 1.0
    Content-Type: multipart/related;
         type="text/html";
         boundary="----_=_NextPart_001_01C6ED7A.EC20BF80"So, it has 4 part specifiers, one for each part in multipart/related. Now, the question to all this is can I determine from the BODYSTRUCTURE object what the root part is (i.e. that it's multipart/related)? Or am I going about this the wrong way (i.e. should I be examining the content-type header first to find out that its multipart/related and the first part is "text/html")?

    Basically, I'm trying to fetch various attributes of a message. In this case, the MIME headers of the various message parts (perhaps I'm stating the obvious but I'm not sure how to better explain what I'm trying to accomplish).
    I've made some "progress". This morning when I continued working with the message described above, all of a sudden, the BODYSTRUCTURE I get back is different and as a result, the BODYSTRUCTURE object generated is different.
    1 uid fetch 148032 (BODYSTRUCTURE)
    * 1 FETCH (BODYSTRUCTURE (("TEXT" "HTML" ("charset" "iso-8859-1") NIL NIL "QUOTED-PRINTABLE" 2792 47 NIL NIL NIL)("IMAGE" "GIF" ("name" "Blank Bkgrd.gif") "<297231021@11102006-1D6D>" "Blank Bkgrd.gif" "BASE64" 202 NIL ("inline" ("filename" "Blank Bkgrd.gif")) NIL)("IMAGE" "BMP" ("name" "ExchangeBabs.bmp") "<297231021@11102006-1D66>" "ExchangeBabs.bmp" "BASE64" 2630728 NIL ("inline" ("filename" "ExchangeBabs.bmp")) NIL)("APPLICATION" "OCTET-STREAM" ("name" "Presence_K1=XItJBkk1xQi8X5JIgeeyjkn9EJTYKfxg9AogMsw3qHMhNnawbZ5wVWrmDFYTq1yP&MODE=IMG") NIL "Presence_K1=XItJBkk1xQi8X5JIgeeyjkn9EJTYKfxg9AogMsw3qHMhNnawbZ5wVWrmDFYTq1yP&MODE=IMG" "BASE64" 732 NIL ("inline" ("filename" "Presence_K1=XItJBkk1xQi8X5JIgeeyjkn9EJTYKfxg9AogMsw3qHMhNnawbZ5wVWrmDFYTq1yP&MODE=IMG")) NIL) "related" ("type" "text/html" "boundary" "----_=_NextPart_001_01C6ED7A.EC20BF80") NIL NIL) UID 148032)
    1 OK FETCH completed.
    bs= BODYSTRUCTURE  (id=89)
         bodies= BODYSTRUCTURE[4]  (id=104)
              [0]= BODYSTRUCTURE  (id=115)
                   bodies= null
                   encoding= "QUOTED-PRINTABLE"
                   subtype= "HTML"
                   type= "TEXT"
              [1]= BODYSTRUCTURE  (id=116)
                   bodies= null
                   encoding= "BASE64"
                   subtype= "GIF"
                   type= "IMAGE"
              [2]= BODYSTRUCTURE  (id=117)
                   bodies= null
                   encoding= "BASE64"
                   subtype= "BMP"
                   type= "IMAGE"
              [3]= BODYSTRUCTURE  (id=118)
                   bodies= null
                   encoding= "BASE64"
                   subtype= "OCTET-STREAM"
                   type= "APPLICATION"
         encoding= null
         subtype= "related"
         type= "multipart"NOTE: The UID differs from the previous example I'd given because I had archived the message and then moved it back to my Inbox.
    Any ideas why the BODYSTRUCTURE reported by the server today is different from what it reported before? I have this message on both an Exchange 2000 and Mirapoint server. 2 days ago they both reported the BODYSTRUCTURE I indicated before, now they both have the BODYSTRUCTURE above.
    PS. Sorry that this issue isn't really Javamail related anymore but I'd appreciate any input.

  • Loading a specific image using servlets

    Hello,
    I have a question regarding a servlet and my HTML. In my HTML page I should load/ reaload some GIF images that are being dynamically created on the serves: drawn with Java 2 D and afterwards GIF encoded. response.setContentType("image/gif");
    GifEncoder encoder = new GifEncoder(img, out);
    in the servlet GraphicServlet.java, for example.
    In my HTML page I want to load this image that is being formed on the server. Here's that piece of code:
    <td><A HREF="http://localhost:8080/servlet/mypackage.myServlet?Nothing! onMouseover="ddrivetip('Click to draw a selected shape', 'yellow', 250)";
    onMouseout="hideddrivetip()">
    <img WIDTH=375 HEIGHT=250 BORDER=0 src="<%
    if (request.getParameter("string")!=null)
    out.print((String)request.getParameter("string"));
    else
    out.print("http://localhost:8080/servlet/mypackage.GraficServlet?undo");
    %>" ISMAP/></a></td>
    The thing is that I want to load in HTML page in a table the image splitted on the the server. Every cell of the table is a part of the image. My question is how I can do that? Assign an id to every part and load that? What parameted should I pass between the HTML page and the server in order to be able to do that? How can I do in order to be able to reload in the browser only that piece of image that suffered modifications?
    Thank you in advance.
    Dani

    Hello,
    I will try to explain in a better way.
    At the present moment the application behaves as it follows:
    1.The Server creates the image and encodes it into GIF
    2. Html displays this image as a server side image map
    3. The image is dynamically umpated in the browser, being modified by user interactions, and modifications are sent to the server
    4. On the server I am splitting this image in subimages (for example, a grid of 4 equal tiles)
    What I'm indending to do is:
    1. What I am trying to do is display in a table in the browser the subimages, each cell holding one part of the entire image, and I don't know what parameter I should use and how, as a selection of the sub-image.
    Here's the fragment where I am loading the entire image in the browser. I don't know how I should modify that in order to be able to load the certain parts on the original images in a table, in my HTML page.
    <td><img WIDTH=375 HEIGHT=250 BORDER=0 src="<%
    if (request.getParameter("string")!=null)
    out.print((String)request.getParameter("string"));
    else
    out.print("http://localhost:8080/servlet/mypackage.GraficServlet?undo");
    %>" ISMAP/></td>
    Thank you, once again.

  • Newbie Help: Java Object to create an image

    Hi there.
    I'm trying to create a Java class that I can call from Coldfusion that will build a GIF file based on parameters.
    The idea is, the Java object opens a "background" gif file and then writes some text onto it and saves the whole thing out as a GIF.
    Bearing in mind this class will be used directly by Coldfusion, and so isn't an applet or an application...can anyone tell me what is wrong with this code as I get a null pointer exception on the getGraphics() line:
    // Methods available to Coldfusion
    public String CreateOverlay( String imageFile, String outPath, String overlayText, int x, int y, String fontFace, int PointSize)
    try{
    Toolkit tk = Toolkit.getDefaultToolkit();
    Image im = tk.getImage(imageFile);
    Gif89Encoder enc = new Gif89Encoder();
    OutputStream out = new BufferedOutputStream(
    new FileOutputStream(outPath)
    Image newimg = createImage(100,50);
    ***** Graphics g = newimg.getGraphics();
    g.drawImage(im, 0, 0, 100, 50, this);
    g.drawLine(0,0,50,50);
    enc.addFrame( newimg );
    enc.encode(out);
    out.close();
    catch (Exception e) {
    System.out.println("Error...");
    e.printStackTrace();
    return "Dont care at the moment";
    Any help to this troubled newbie would be appreciated.

    Hi Kurt,
    You must call "setVisible(true)" on your Frame before
    creating the image.But, the thing is, this object doesnt have (or need) a GUI. Its just an object that sits on the server and its methods are called to generate an image on disk. Basically what happens is Coldfusion receives information from a user and it loads the java object, calls a method which then generates a new GIF file that is made up of a simple button background and some text (entered by the user)....it then returns the name of this file to Coldfusion and Coldfusion stores it in a database for later retrieval.
    In simple terms:
    COLDFUSION===========
    1. Creates an instance of the JAVA Object
    2. Call the generateGif method passing an image filename and some text eg:
    newFile=c.GenerateGif( "simplebutton.gif", "Some text for button");
    JAVA OBJECT========= (GenerateGif method)
    1. Load the GIF simplebutton.gif
    2. Create a new blank image
    3. Draw the loaded GIF onto the blank one
    4. Write the Text ("some text for button") onto the image
    5. Take the image and encode it to GIF format
    6. Write this GIF to disk
    7. Return the filename of the new GIF image just created
    8. Finish
    As you can see, I dont want or need a GUI.....
    Is this possible ?
    Thanks in Advance,
    Tony Johnson

  • Make a image file

    it is possible to make a image file with thee thing i've done in a jPanel (like .gif, .jpeg or others)???
    if not with a JPanel but with other component or the applet enterily, please said it
    thx for help
    scuse with my english

    What are you trying to capture? The whole panel with components or just a Graphics pallete?

  • ImageIcon + XMLEncoder ?

    Hi,
    my problem is:
    I want to use ImageIcons in a graph app to show the begin and end of statecharts. So my question is:
    Is it possible to encode/decode the gifs with the XMLEncoder/decoder?
    As I tried the gifs haven't been decoded and so in my graph the gifs missed.
    Is there any known bug or something else?
    Greets
    Christoph

    Did you have any luck? As I am trying to do the same thing..
    Thanxs in advance..

  • Displaying icon file associated with the exe file.

    Hi ,
    I want to display the icon file associated with the an exe file.
    I know that it is posssible to (Using wni32 API's) it is possible to extract the ico file. But I don't know how I can display it in my Java application.
    It will be great if anybody can throw light on it.
    With Regards,
    Praveena

    Hi,
    what functions do you both have in mind when talking about extracting the icon file using JNI and Win32 API? I know there is ExtractIcon in VisualBasic and Delphi that works for this, yet I do not see anything similar in JNI.
    Thanks in advance,
    Gleb.
    P.S. You should be able to display .ico files after decoding them & encoding them into gif/jpg in JIMI (Sun package for advanced image/graphics management).

  • Animated .gif in JPanel

    Hello,
    I'm trying to render an animated .gif in a JPanel. I'm overriding paintComponent as follows:
       public void paintComponent(Graphics g)
          super.paintComponent(g);
          // center the background image.
          //backgroundImage is an Image
          if (backgroundImage != null)
             g.drawImage(backgroundImage, (this.getWidth() - backgroundImage
                   .getWidth(this)) / 2, (this.getHeight() - backgroundImage
                   .getHeight(this)) / 2, this);
       }The problem: I'm only getting the first frame displayed. What do I need to do to properly display the animated image?
    Thanks.
    Marc

    Adding a JLabel is not convenient, nor is it the proper way to do it. The panel has other components and coming up with a layout manager that will overlay components is not the proper thing to do.
    Creating a Thread is also not the proper thing to do.
    I found a solution that works fine. Instead of using an Image, I create an ImageIcon and use that to display the animated gif.
       public void paintComponent(Graphics g)
          super.paintComponent(g);
          // center the background image.
          // backgroundImage is an ImageIcon
          if (backgroundImage != null)
             g.drawImage(backgroundImage.getImage(), (this.getWidth() - backgroundImage
                   .getIconWidth()) / 2, (this.getHeight() - backgroundImage
                   .getIconHeight()) / 2, this);
       }Thanks for your help.

  • Animated GIF Image on a JPanel.

    How can I display an animated GIF image on a JPanel? It should animate after displaying.
    Regards

    I think this code should display an animated GIF image on a JPanel.
    -Mani
    import javax.swing.*;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.*;
    public class Animation {
    public static void main(String args[]) {
    JLabel imageLabel = new JLabel();
    JLabel headerLabel = new JLabel();
    JFrame frame = new JFrame("JFrame Animation");
    JPanel jPanel = new JPanel();
    //Add a window listner for close button
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    // add the header label
    headerLabel.setFont(new java.awt.Font("Comic Sans MS", Font.BOLD, 16));
    headerLabel.setText("Animated Image!");
    jPanel.add(headerLabel, java.awt.BorderLayout.NORTH);
    //frame.getContentPane().add(headerLabel, java.awt.BorderLayout.NORTH);
    // add the image label
    ImageIcon ii = new ImageIcon("d:/dog.gif");
    imageLabel.setIcon(ii);
    jPanel.add(imageLabel, BorderLayout.CENTER);
    frame.getContentPane().add(jPanel, java.awt.BorderLayout.CENTER);
    frame.pack();
    frame.setVisible(true);
    }

Maybe you are looking for

  • ITunes is trying to synch a track which is no longer in my Library

    A couple of weeks ago, iTunes had a problem adding one particular track to my iPod. It has had similar problems before - generally solved by creating a new MP3 of the file (within iTunes) and deleting the old one. This time, however, that didn't work

  • Pdfescpage error while printing

    I keep getting errors when trying to print a document from Acrobat Pro XI to my EPSON EPL-5700i.  I use a Mac and the PDF's from Preview print fine. Error is: Process:           pdftoescpage [1320] Path:              /Library/Printers/EPSON/LaserPrin

  • Podcasts aren't working

    i subscribed to a podcast and i went to put it on my ipod and did everything like i would except went into the podcast section and said to automatically update the podcasts....but when i went to my ipod after thinking they had been downloaded nothing

  • Error for Photoshop Elements 3 & Horrible Response From Support

    I own Adobe Photoshop Elements 3. It was installed on my Macbookpro and my G5 desktop. The G5 died. I tried to install the software on my new iMac. It let me get all the way through installation then gave me this error message: Could not complete you

  • Cannot configure parameter FORMULA_FILE_NO in task /CPMB/IOBJ_SOURCE_MD_CON

    Hi When I am trying load data from Bi infoobject to BPC dimension following error I am getting. "Cannot configure parameter FORMULA_FILE_NO in task /CPMB/IOBJ_SOURCE_MD_CONVERT" Can any body give me suggestion to resolve this issue Mahi