JPEG/GIF image to BASE64

Hi,
I like to convert JPEG/GIF or any type of image into BASE64 format and Viceversa. Can somebody provide me the java code for doing this.
Cheers,
Siva Maranani.

Rather than use an undocumented API, I would suggest a 3rd party library for Base64 encoding such as the one that I wrote:
http://ostermiller.org/utils/Base64.html
It even has several convenience methods for encoding files:
static void      encode(File fIn)
Encode this file in Base64.
static void      encode(File fIn, boolean lineBreaks)
Encode this file in Base64.
static void      encode(File fIn, File fOut)
Encode this file in Base64.
static void      encode(File fIn, File fOut, boolean lineBreaks)
Encode this file in Base64.

Similar Messages

  • Need help to create report with jpeg/gif image

    Hello,
    I need help with creating a form with a special jpeg/gif seal. I never done this Java. Until now, I created all forms with ansi C++ with HP escape characters to draw lines, boxs, and text. This form will contain boxes which is populated with database information read from a text file.
    Since this form contains a special seal on the upper right, I don't think it can be done with old fashion ansi C++. How can I create a form with Java and create it as a simple exe to just print the form to a specified printer.
    Thanks,
    John

    Hi,
    I am creating a form with boxes (lines and text). What is special about this form is that it has an image jpeg or gif at the top right corner. Is is a state department seal. Up to this form, I had used ansi C++ and print out escape HP character to print out the lines, boxes, and text. I have no idea how to print out the image. I am new to JAVA and only 1 class in it. Is there sample code out there to create this type of form with the image? I need a starting point.
    Thanks,
    John

  • Save Applet as a jpeg/gif image

    I wrote a small applet to draw some lines.
    it work fine.
    What i want to know is how can i save this applet to a jpeg/gif file.
    (Assume there is a Button in the Applet or Even in the HTML page; when click the button needs to save the applet as an image file)
    is it possible??
    import java.applet.*;
    import java.awt.*;
    public class Test extends Applet {
       int width, height;
       public void init() {
          width = getSize().width;
          height = getSize().height;
          setBackground( Color.black );
       public void paint( Graphics g ) {
          g.setColor( Color.green );
          for ( int i = 0; i < 10; ++i ) {
             g.drawLine( width, height, i * width / 10, 0 );
    <applet code="Test" width="300" height="300">
    </applet>
    Message was edited by:
    jugp

    After finding out some facts i tried to do like this;
    but still having some runtime exceptions....
    need help from anybody!!!
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.BufferedImage;
    import javax.imageio.ImageIO;
    import java.io.File;
    import java.io.IOException;
    public class Test extends Applet implements ActionListener{
       int width, height;
    Image backbuffer;
       Button save;
       public void init() {
          save = new Button("save");
          add(save);
          save.addActionListener(this);
               width = getSize().width;
          height = getSize().height;
          setBackground( Color.black );
       public void paint( Graphics g ) {
          g.setColor( Color.green );
          for ( int i = 0; i < 10; ++i ) {
             g.drawLine( width, height, i * width / 10, 0 );
       public void actionPerformed(ActionEvent e) {
         String cmd = e.getActionCommand();  
         if (cmd.equals("save")){
                 BufferedImage bufferedImage = new BufferedImage ( width, height,
                       BufferedImage.TYPE_INT_BGR  );
                        bufferedImage.createGraphics().drawImage( backbuffer, 0, 0, this);
                   try {
                        ImageIO.write( bufferedImage, "jpg", new File ( "image.jpg" ) );
                   } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
    <applet code="Test" width="300" height="300">
    </applet>
    */

  • Loading JPEG/Gif images causes Out Of Memory Error

    Hello Java gurus, please shed some light on this.....
    I am not a java newbie, but I am a java newbie in the area of dealing with graphics. I am using JDK 1.4.2_01 on Win XP with 2.4ghz and 512 RAM. When I try to read in a (or a few) JPEG image into a JLabel using ImageIcon, I get an out of memory error everytime. This happens whether I am reading the image out of a jar file or out of a local directory. The JPEG's are 8.5" x 11", and range between 150kb to 900kb. I am trying to load approximately 10 images in a JTabbedPane using new JLabel(ImageIcon) on individual JPanels (one JPanel for each JPEG). Now I get the java.lang.outofmemory error whether I try to load 1 image or 10 images. Anyone got a clue as to what I am doing wrong? I actually do get one image loaded before the error gets thrown. So I do know that it is trying to load the right image. What is going on here? Is it an ImageIcon problem, or are there others who have run into this. It has brought this project to a grinding halt, and I had thought this would be the easier part!!!! Please help me out gurus! Thanks!

    What options/values are you suggesting that I set? Or do you mean something else? Thank you for any ideas that can help me solve this problem. I never had any issues dealing with using ImageIcon for toolbar button graphics (file sizes of 1-3kb), but now with dealing with full page graphics I have run into a brick wall with this out of memory error.

  • Image (jpeg, gif) display in AWT layout manager

    Goodmorning All,
    I am looking for some help, a hint on my AWT Layout challenge i have.
    Example GUI_1:
    =========================
    Window border..................[_][x]..
    =========================
    [label]....|display_area|....[button].
    [label]....|display_area|....[button].
    ...............|display_area|....[button].
    ...............|display_area|....[button].
    ...............|display_area|..................
    =========================
    ...........................................[QUIT].....
    =========================
    I want to
    - display a picture in the "display area" of the this GUI
    - put labels left of it with some text
    - put a couple of buttons right of it, through which i am able to manipulate the image
    Questions:
    *1. Is it (even) possible to display an (jpeg,gif) image in the "display area" while using a layout manager?*
    Surfing over the internet...so far i only have found applet-examples that use the full gui surface of the applet to display an image via the g.drawImage (imagename, x,y); without any gui elements (labels, buttons) beside it.
    *2. What kind of AWT gui element do i need at the location of the "display area"?*
    Is is possible to use a CANVAS or do i need somethen else? (e.g. glue an image on a button)
    *3. Is is possible to display an ANIMATION (series of sequences jpeg, gifs) in the display area?*
    I already found out how to locate and load the images (via mediatracker).
    Now i need to find a way to "paint" the loaded images in the GUI.
    *4. Is this even possible with AWT layout or do i need to switch to SWING layout?*
    I have not used Swing yet, cause i'm working my way up through the oldest gui technologie first.
    *5. Do know any usefull websites, online tutorials (on awt and displaying images) that can help me tackle my challenge?*
    Thank you very much for your hints, tips and tricks

    A link as Gary pointed out is the best way to see what the problem may be.
    Did you save the image to your working folder and have you defined a site pointing to this folder.
    Defining a site helps Dreamweaver track and organize the files used in this site.
    http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_14028
    If you can't see the image, this means that the path to the image is incorrect.
    Nadia
    Adobe Community Expert : Dreamweaver
    Unique CSS Templates | Tutorials | SEO Articles
    http://www.DreamweaverResources.com
    Web Design & Development
    http://www.perrelink.com.au
    http://twitter.com/nadiap

  • Can assets be images of type jpeg,gif,Tiff,etc... ?

    Hi,
    I am working  on ES2.
    I am able to take PDF file as form to the  my  process. Here  my  new requirement is   in addition to  pdf  I need to take all types  of  images
    say jpeg,gif, and Tiff  as  input to my  process.  But I am not able to do that bcas Workbench only  takes *.pdf as input.
    If you have other extensions  expect  pdf,  while   taking the asset into the  start activity, I  could  not  find that  file in the  application.
    Please help me in this regard how  workbench takes  all image files as inputs into  the  process.
    Thanks
    Praveen.

    Hi Scott,
    Thanks for your reply.
    Yes   I  have to use as image file as form  to the process.
    I am using  Adobe LC ES2.
    Let  me explian my  requirement :  I have  scanned image   and  need to use that image as input to the process i mean image as form  to the process.
    I will invoke the process then  scanned image should come as form  in the  workspace .
    Please help in this regard.
    Thanks
    Praveen.

  • How combine a jpeg image & animated gif image & save  it as GIF ?

    i have an jpeg image, & also aminated gif image, how do i place the animated gif image over (in the center of the image) a jpeg image & save it as gif file ??

    First thing you need to do is stop thinking in terms of file formats once the files are in photoshop they are all the same. The exception being vector vs raster. But in this instance the process is rteally the same so 6 on one hand a half a dozen on the other. Or as some would say Tomatoe, tomahtoe(mispelled on purpose).
    The jpeg I would assume is the background image and the gif image is the fore ground object. Open the jpeg, and then place the gif file. As long as the fore ground object has transparency, your job is pretty much done. If not, then it will be up to you to mask what you want to keep vs what you don't and apply that selection to the foregrounds layer as a mask.
    Google the net or skim the users manual for the keywords - mask, selections, quickmask, pen tool, paths. Each of these can in one way or another take care of your issue.
    It would be worth your time to also go through the numerous videos about photoshop and see how its done.
    Either go to adobe tv,
    Itunes podcasts
    or one of the following web sites:
    http://kelbytv.com/
    http://creativesuitepodcast.com/

  • Error while loading a logo .gif image to the banner

    Hi all,
    I'm running Portalea on NT platform and I receive the following error, trying to load a gif image as a logo to the banner (this is in spanish but I hope you can understand it):
    Wed, 27 Dec 2000 07:03:25 GMT
    ORA-06510: PL/SQL: excepcisn definida por el usuario no tratada
    ORA-06512: en "PORTAL30.WWDOC_DOCU_BRI_TRG", lmnea 60
    ORA-06510: PL/SQL: excepcisn definida por el usuario no tratada
    ORA-04088: error durante la ejecucisn del disparador 'PORTAL30.WWDOC_DOCU_BRI_TRG'
    DAD name: portal30
    PROCEDURE : PORTAL30.wwptl_banner.savecustom
    URL : http://ORACLE1:80/pls/portal30/PORTAL30.wwptl_banner.savecustom
    PARAMETERS :
    ===========
    ENVIRONMENT:
    ============
    PLSQL_GATEWAY=WebDb
    GATEWAY_IVERSION=2
    SERVER_SOFTWARE=Apache/1.3.12 (Win32) ApacheJServ/1.1 mod_ssl/2.6.4 OpenSSL/0.9.5a mod_perl/1.22
    GATEWAY_INTERFACE=CGI/1.1
    SERVER_PORT=80
    SERVER_NAME=ORACLE1
    REQUEST_METHOD=POST
    QUERY_STRING=
    PATH_INFO=/pls/portal30/PORTAL30.wwptl_banner.savecustom
    SCRIPT_NAME=/pls
    REMOTE_HOST=
    REMOTE_ADDR=192.168.100.224
    SERVER_PROTOCOL=HTTP/1.1
    REQUEST_PROTOCOL=HTTP
    REMOTE_USER=
    HTTP_CONTENT_LENGTH=6443
    HTTP_CONTENT_TYPE=multipart/form-data; boundary=---------------------------7d02753210f0280
    HTTP_USER_AGENT=Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)
    HTTP_HOST=oracle1
    HTTP_ACCEPT=application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-comet, */*
    HTTP_ACCEPT_ENCODING=gzip, deflate
    HTTP_ACCEPT_LANGUAGE=es
    HTTP_ACCEPT_CHARSET=
    HTTP_COOKIE=portal30=AB515A5F55262E576590647AC04D98A8EF1D5A6F56D19ECCD710BDB4A08D2354903C0CA288FDE0C9283E116C71C00B1B3821CEAB7A24979CFF326F4979143EE1FD147BC097C2AD7705313C93DAB32D8 4A6CF71C26B267CC0B2FEA03B385A2E84; portal30_sso=7452540140821A6010973F5CAC7E7D17C7498F309E15C228015C1C0546A702F5AFDE500B69BDCB8DE5C29DD726FC8DEEE85A1DC979ECC7B8A6A16CADEF1DAB0C0ACEC11897D5B99B1033884D61307BEA7AE581C 8AB988C8CBBBDCE6174BA01F6
    Authorization=
    HTTP_IF_MODIFIED_SINCE=
    null

    Hi,
    No errors was found in the installation log. I'm looking in the WWDOC_DOCUMENT$ table and found records that make references to my previous tries to upload the logo image. In order to make others tries, how can I delete this information? Are references to this files in any other table?.
    I'm looking over the solution provide by Laurent Baresse, refering to the NLS_LANGUAJE problem ... (Thanks Laurent).
    Best regards
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Karthika Siva ([email protected]):
    Fernando,
    Are you able to upload any documents into a content area? Please look at your installation log file (install.log) for any errors that may have occured during the installation of the product. Also make sure that the tablespace containing the WWDOC_DOCUMENT$ table is not full.
    Karthika<HR></BLOCKQUOTE>
    null

  • 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

  • Gif images

    will nokia 6600 support gif images? when i send a gif image to my nokia 6600 it automaticaly chage the picture format to jpeg.. i wanna set a gif image as my mobile operator logo.. as Mr.Petrib told me.. i change the operator logo using FExplorer and it works fine..thanks for that..but still it has white background for all the logo beeing the picture is in jpeg format..can i get this issue resolved?

    hello people...
    i didn't get any answer for my previous question... could any one give an answer for that.. and i would like to know what is the format of picture message? can we create our own picture message and use it in 6600?

  • 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.

  • Looking for comprehensive program to create pdf file from gif image

    Hello,
    I'm looking for a program that can transform gif image file into pdf file. It is very importent to keep the same quality of the output document as the original image.
    I've seen Bridge CS5 in action and was very much disapointed, because the original gif image had 2 colors: black and white, took 60k Byte A4 paper size. But the output pdf file became somehow to 700k Byte size. When our proffi tried to lower the ppi or quality bar there was direct impact on the image quality.
    Long time ago Photoshop was able to export images as pdf files and one of the options of the pdf file was to keep the original image as gif, not as jpeg. Because jpeg is very costy format for black-white images and no-one wants to waste memory in vain, so I do not like to save pdf files of 1MB size for an image that takes 100k in gif.
    I do understand that nowdays using Photoshop to save pdf files is not the option anymore, isn't it ?
    What program can you suggest me to use ? I still prefer to use Adobe products, as long as I can, through I'm starting to get scared of sharp decline in quality.
    Thank you in advance.
    sincerely,
    Al

    No, I didn't. The last time I saw it, it was looking just as a regular Reader with a little more options and with an addon to MS-Office, to allow to save MS documents to pdf from inside MS-Office user interface products, and frankly, I do not highly admire there products at all, so I do not have MS-Office installed. But it was also long time ago. If the situation did changed since than,  I will try it.
    Thank you very much.
    I've just tried the Acrobat. It worked great ! Thank you. Just not all the images have options how to save them in pdf file, but that's ok for now

  • Gif images blurry - asha302

    Hello people. I have this issue with relatively large GIF images, they look blurred when I use the zoom-in. They actually don't zoom. I solved this using the editor and saving them as JPGS but I would like to know if this is something in common with all the Asha phones.
    Thanks in advance.
    Solved!
    Go to Solution.

    That is a bug in the ‘new’ gallery which was introduced 2010 with Series 40 6th Edition PR9.1. Some anti-alias filter is applied (to make JPEG look better, breaks GIF and PNG). By the way, if you zoom-in and zoom-out again, JPEGs get better. Or stated differently: Normal behaviour because that bug is not important to Nokia.

  • Some of Photo (JPEG)-compressed images by Flash Pro are not shown in AIR app (3.7/3.8)

    Does anyone see this issue happening? In Flash Pro it's OK, but in AIR, it's broken.
    https://bugbase.adobe.com/index.cfm?event=bug&id=3558175
    Problem Description:
    Some JPEG-compressed images in swc produced by Flash Pro CS6 is not shown in AIR.
    Steps to Reproduce:
    1. Create a fla with Flash Pro CS6
    2. Put a png image in it and open the property of the image to make sure its compression option is Photo (JPEG)
    3. Produce an swc out of the fla
    4. Create an AIR app that shows the contents in the swc
    Actual Result:
    All images are shown
    Expected Result:
    Some of the images are not shown (nothing is shown where they are supposed to be)
    Any Workarounds:
    Use Lossless (PNG/GIF) for all images

    i was able to get it to work from a suggestion in another thread: if you write a JSFL that goes through all your bitmaps and makes sure they do not uset he default compression of the document, but instead use custom compression (it can match the default however). this worked for me

  • Error in downloading .gif image

    hi frndz
    I am writing an application which downloads the image from server
    for .jpeg, .jpg, .png its working fine but for .gif images it gives me the error: ArrayIndexOutOfBoundException
    Code for downloading Image is:
    ContentConnection connection = (ContentConnection) Connector.open(url);
    DataInputStream iStrm = connection.openDataInputStream();
    // two methods are used to download IMAGE
    // (I) If length available , (II) If length not available
    int length = (int) connection.getLength();
    // (Method I :) ContentConnection includes a length method
    if (length != -1)
    imageData = new byte[length];
    iStrm.readFully(imageData);
    // (Method II :) If Length not available...
    else
    ByteArrayOutputStream bStrm = new ByteArrayOutputStream();
    int ch;
    while ((ch = iStrm.read()) != -1) bStrm.write(ch);
    imageData = bStrm.toByteArray();
    if (bStrm != null) bStrm.close();
    // Create the image from the byte array
    img = Image.createImage(imageData, 0, imageData.length-1);
    When I print Image length its zero and also imageData length is zero
    is there any other method to download .gif images
    thanks
    alpesh

    the problem is not in displaying image
    and by the way i am testing this on N70
    problem is in downloading
    i.e. image length is zero as well asif I dont consider image length the downloaded bytes are zero
    alpesh

Maybe you are looking for

  • How do I copy iTunes from external hard drive to iMac?

    How do I copy iTunes from external Hard drive to iMac?

  • DIFFERENT Currencies for PO Line Item

    Hi Frndz, On a Purchase Order with more than one line item, the different items can have prices with DIFFERENT currencies? In my case first line item currency is getting copied to all line item and after that, currency feild is grayed out. But client

  • Can't get unit to power on after charging.

    Unit appears to be fully charged on computer; I can see the green light indicator. But when I pull it off, I can't get my iPod to power on. I've had the unit for a few years and haven't had any problems like this. I've already "restored" it and I'm l

  • How to set height of JTable Header ?

    How to set height of JTable Header and set the text to another size ?

  • HELP PLZZZ

    When I click on 2 photos a message appears saying "a calling thread cannot access this object because a different thread owns it" I have no clue how to fix this PLZZZ HELP I just started this class so I don't know many key words here is my code ' Mat