How to convert base64 data to an image

Hello, my enterprise application is receiving base64 enocoded image data in an xml file. Now I need to convert it to a native image formats like jpeg/jpg/tiff/pdf etc. Does anybody know if there are any Java apis (both free/paid) which let you do this. Actually I would not have any idea of what type of image it was when it was initially encoded to base64 format. I am looking for an API/technique that can convert base64 data to any image depending on what I want at runtime.
Thanks a lot in advance.
R

Hi there,
I've had to deal with exactly the same problem myself. The images I had to deal with were all TIFF files, and that was okay, I'd say one of your first steps would be to find out what format these images are in.
I used a SAX Content Handler to pull the base 64 image data out of the XML into a String, and then converted the Base 64 String into a byte array. From there I could either simply write the byte array to a file, or if I wanted use ImageIO to create an Image object, work with the metadata or even save it in a different format, though I never actually did that.
Anyway, here is some code I whipped up to convert the String to a byte array, then write the byte array to disk. Let us know how you get along!
      * Writes a byte array to a file.
      * @param result          String containing base64 image data     
      * @param fileName     File name to write the converted image to
     public static void writeTiff(byte[] result, String fileName) throws IOException {          
          FileOutputStream out = new FileOutputStream(fileName, true);
          out.write(result);
          out.close();
      * Converts a String of base 64 image data, captured from XML, into a byte array.
      * @param      image     A Base 64 String          
      * @return      byte[]          
     public static byte[] convertTiff(String image) throws IOException {          
          byte[] result = new sun.misc.BASE64Decoder().decodeBuffer(image);
          return result;
     }

Similar Messages

  • How to convert numeric data to binary decimal in java

    How to convert numeric data to binary decimal in java Pleas egive me code example

    There is no numeric data. It's all binary. If you're talking about Strings, look at the Integer class.

  • How to convert julian Date into Calendar Date

    Hi,
    I want convert julian Date to calendar Date (mm/dd/yyyy or mm/dd/yy format) in java.
    Can any one help me how to convert julian date to calendar Date.
    Thanks,
    Krishore.

    import java.util.*;
    import java.text.*;
    public class jdate {
    Calendar date;
    public jdate(int j)
    date = Calendar.getInstance();
    date.set(Calendar.DAY_OF_YEAR, j);
    public String toString()
    SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
    return (formatter.format( date.getTime() ));
    public static void main(String args[])
    if(args.length == 1)
    int j = Integer.parseInt(args[0]);
    jdate julian = new jdate(j);
    System.out.println("Julian date(" + j + ") = " + julian.toString());
    }

  • How to convert a date field with format (dd,mm,yyyy) to format (mm,dd,yyyy)

    Hello.
    How to convert a date field with format (dd,mm,yyyy) to format (mm,dd,yyyy)
    I have text field which has a databind to a date field. When I click on it, we can select the date, it is added on the format (dd,mm,yyyy). When I want to insert this date field to a database It doesnu2019t allow me to do it because it will only accept date field on the format (mm,dd,yyyy)
    I tried to store this format on a date variable and I get a message saying that is impossible to convert a string into a date.
    Regards,
    Jose

    Hi Jose,
    usually you format strings in c# like
    string.Format("{0:yyyyMMdd}", insertyourstring);
    in your case
    string.Format("{0:MM/dd/yyyy}", insertyourstring);
    [look here|http://idunno.org/archive/2004/14/01/122.aspx]
    there are more details
    if everything fails split the string with Mid()
    or ask me
    lg David

  • How to convert system Date into DD-MMM-YYYY Format

    hi friends,
    please help me How to convert system Date into DD-MMM-YYYY Format.
    Regards
    Yogesh

    HI..
    data: w_dt(11) type c,
             w_month(2),
             w_mon(3).
    w_month = p_date+4(2). **p_date = given date**
    case w_month.
    when '01'.
    w_mon = 'Jan'.
    when '02'.
    w_mon = 'Feb'.
    when '03'.
    w_mon = 'Mar'.
    when '04'.
    w_mon = 'Apr'.
    when '05'.
    w_mon = 'May'.
    when '06'.
    w_mon = 'Jun'.
    when '07'.
    w_mon = 'Jul'.
    when '08'.
    w_mon = 'Aug'.
    when '09'.
    w_mon = 'Sep'.
    when '10'.
    w_mon = 'Oct'.
    when '11'.
    w_mon = 'Nov'.
    when '12'.
    w_mon = 'Dec'.
    endcase.
    Now...
      concatenate p_date6(2)  '-'  w_mon  '-'   p_date0(4)  into w_dt.
    write w_dt.

  • How to convert siebel date to following format?

    Hi,
    How to convert siebel date to following format?
    01-01-2011 5:00 AM (dd-mm-yyyy hh:mm AM)
    01-JAN-2011 5:00 AM (dd-MON-yyyy hh:mm AM)
    01/01/2011 5:00 AM (dd/mm/yyyy hh:mm AM)
    Please suggest functions for conversion. Have tried few but didnt work.
    Thanks.

    Excerpts from
    http://bipconsulting.blogspot.com/2010/01/my-date-doesnt-like-me-with-siebel.html
    ".. the date data generated by Siebel with the IO is in ‘MM/DD/YYYY HH:MI:SS’ format, so it is something like ‘10/09/2008 05:31:13’. And BI Publisher doesn’t recognize that this is a date data because it’s not presented in the ‘Canonical’ format!.."
    "...There are two possible and reasonable workarounds to overcome this issue. The first one is to use one of the Siebel’s extended function ‘totext()’ to convert the Siebel date format to the ‘Canonical’ date format before the BI Publisher’s date related function comes in..."
    Please read on the above link to find out how to actually resolve this issue.
    Good Luck
    (please if this provides a solution for you grant the points and close this thread. Thanks!)
    Jorge

  • How to convert CLOB data (now it is in html format) to Normal text format

    Hi,
    Can anybody let me know the solution for how to convert CLOB data into normal Text.In my case the table column having CLOB datatype and the data is in html format.when i run the report the column is displaying html tags .Now i need to convert that html tags into normal text.
    Pl. let me know if any one know the solution.
    Regards,
    Thulasi.K

    LONG has been depricated since 8i so I don't believe there is a general solution to go backwards short of reloading the data.
    Justin

  • How to convert mongodb data  to oracle

    The requirement is I need to convert the mongodb or JSON data which is provided to us in Oracle format
    so that it can be used in Oracle Data Integrator ODI
    Edited by: 918554 on Aug 9, 2012 10:37 PM
    Edited by: 918554 on Aug 9, 2012 11:02 PM
    Kindly reply soon its urgent
    Edited by: 918554 on Aug 9, 2012 11:03 PM

    918554 wrote:
    how to convert mongodb data to oracleThis is NOT an Oracle problem or solution.
    http://www.mongodb.org/display/DOCS/SQL+to+Mongo+Mapping+Chart

  • How to convert a data set into a xml data and vice versa

    i am new to oracle with xml..
    my aim is to convert a data set into a xml data and vice versa..
    my work is as follows...
    my query:
    select rggpk,rggcode,rggname from ms_regiongeo
    to convert a data set into a xml*
    select XMLType(trim(replace(dbms_xmlgen.getXML('select rggpk,rggcode, rggname from ms_regiongeo'),'<?xml version="1.0"?>',''))) XML_DATA from dual;
    (this works fine and output of this query is as follows..)
    <ROWSET>
    <ROW>
      <RGGPK>201</RGGPK>
      <RGGCODE>Asia</RGGCODE>
      <RGGNAME>Asia</RGGNAME>
    </ROW>
    <ROW>
      <RGGPK>1</RGGPK>
      <RGGCODE>OTH</RGGCODE>
      <RGGNAME>Others</RGGNAME>
    </ROW>
    <ROW>
      <RGGPK>21</RGGPK>
      <RGGCODE>COB</RGGCODE>
      <RGGNAME>Africa and Yemen</RGGNAME>
    </ROW>
    <ROW>
      <RGGPK>2</RGGPK>
      <RGGCODE>AUS</RGGCODE>
      <RGGNAME>Australia</RGGNAME>
    </ROW>
    <ROW>
      <RGGPK>23</RGGPK>
      <RGGCODE>IND</RGGCODE>
      <RGGNAME>Indian Sub Continent</RGGNAME>
    </ROW>
    <ROW>
      <RGGPK>24</RGGPK>
      <RGGCODE>TVM</RGGCODE>
      <RGGNAME>North America</RGGNAME>
    </ROW>
    </ROWSET>
    and to reverse this process, I tried a query like this..*
    select EXTRACTVALUE (XML_DATA,'ROWSET/ROW/RGGPK') as EMP_ID
    from(
            select XMLType(trim(replace(dbms_xmlgen.getXML('select rggpk,rggcode, rggname from ms_regiongeo'),'<?xml version="1.0"?>',''))) XML_DATA from dual
    )tab1but failed.. and raised with an eror: ORA-19025
    help me..
    regards,
    john

    Hi-
    my aim is to convert a data set into a xml data  You can refer to the below posts
    Adding namespace to XML output
    Re: how to convert table data in xml format based on the xsd.

  • How to convert a date value into week value?

    How to display the date value like '20010203'
    into the week number of the year 2001?
    When i type in the following sql
    select week(chg_time) from site;
    I got this error message
    ORA-00904: invalid column name

    use the to_char function, to format the date into a week number (then you might need to convert that to a number using to_number)
    select to_char( sysdate, 'WW') from dual`
    a description of datetime formats: http://download-west.oracle.com/otndoc/oracle9i/901_doc/server.901/a90125/sql_elements4.htm#48515

  • How to convert the date time from MM-DD-YYYThh:mm:ss to YYYY-MM-DDThh:mm:ss format

    Hi All,
    I have a requirement in my project like to convert the date time from one format to another.my situation is like to convert the date time from MM-DD-YYYThh:mm:ss to YYYY-MM-DDThh:mm:ss format. I am using the soa suite 11.1.1.6.
    Can any one suggest me how to convert in the BPEL transformation.
    Thanks,
    Sanju.

    Hi Sanju,
    Store the date to be converted into a variable viz. dateVar. Now, process an expression in assign as: xp20:format-dateTime($dateVar,'[Y0001]-[M01]-[D01] [h]:[m01]:[s01]').
    Regards

  • How to convert XML data into binary data (opaque data)

    Hi,
    I am trying to develop a process that delivers files after reading data from a database.
    However, it is required not to deliver the data immediately. We want to perform some checks before the files get written.
    So the way we want to design this is,
    1. Read data from database (or any other input). The data is in XML format (this is a requirement, as in general, we have xml data)
    2. This data is written, opaquely, to a JMS queue that can store binary data, along with what is the filename of the file that would be written (filename is passed using JMS Headers)
    3. When required, another process reads the JMS queue's binary data, and dumps into a file
    The reason I want to use opaque data while inserting in the JMS queue is, that enables me to develop a single process in Step 3 that can write any file, irrespective of the format.
    My questions are
    1. How to convert the xml data to opaque data. In BPEL I may use a embedded java, but how about ESB. Any other way....?
    2. how to pass filename to the jms queue, when payload is opaque. Can I use a header attribute...custom attributes?
    3. Which jms message type is better for this kind of requirement - SYS.AQ$_JMS_BYTES_MESSAGE or SYS.AQ$_JMS_STREAM_MESSAGE

    Ana,
    We are doing the same thing--using one variable with the schema as the source of the .xsl and assigning the resulting html to another variable--the content body of the email, in our case. I just posted how we did it here: Re: Using XSLT to generate the email HTML body
    Let me know if this helps.

  • How to convert BLOB data into string format.

    Hi,
    I have problem while converting blob data into string format.
    for example,
    Select dbms_lob.substr(c.shape.Get_wkb(),4000,1) from geotable c
    will get me the first 4000 byte of BLOB .
    When i using SQL as i did above,the max length is 4000, but i can get 32K using plsql as below:
    declare
    my_var CLOB;
    BEGIN
    for x in (Select X from T)
    loop
    my_var:=dbms_lob.substr(x.X,32767,1)
    end loop
    return my_var;
    I comfortably convert 32k BLOB field to string.
    My problem is how to convert blob to varchar having size more than 32K.
    Please help me to resolve this,
    Thanx in advance for the support,
    Nilesh

    Nilesh,
    . . . .The result of get_wkb() will not be human readable (all values are encoded into some binary format).
    SELECT utl_raw.cast_to_varchar2(tbl.geometry.get_wkt()) from FeatureTable tbl;
    -- resulting string:
        ☺AW(⌂özßHAA
    Å\(÷. . . .You may also want to have a look at { dbms_lob | http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_lob.htm#i1015792 } "The DBMS_LOB package provides subprograms to operate on BLOBs, CLOBs, NCLOBs, BFILEs, and temporary LOBs."
    Regards,
    Noel

  • How to convert the data decoded by MJPEG Decoder MFT into RGB32

    I try to play .avi file(Motion JPEG) with MJPEG Decoder MFT and
    My ColorConverter MFT to convert into RGB32 by using the Media Foundation.
    The output format of MJPEG Decoder MFT is YUY2.
    So, I implemented My ColorConverter MFT to convert YUY2 into RGB32.
    I set the  topology to play .avi file and  to convert into RGB32.
    But I got a MEError event with ME_ARITHMETIC_OVERFLOW in
    IMFMediaEvent->GetStatus(&hrStatus)); after the event MESessionTopologyStatus.
    So,the file isn't started to play.
    The created topology is follow.
      Source-> MJPEG Decoder MFT -> My ColorConverter MFT -> EVR
               Format:                    YUY2                                         
    RGB32
    Why do the error occur in processing to convert the data decoded by MJPEG Decoder MFT
    into RGB32?
    Please tell me a appropriate way to convert the data decoded by MJPEG Decoder MFT
    into RGB32.

    You've got the High Speed Data Reader.vi as a starting point. That will retrieve the binary data and plot it on a chart. From the array of sgl's created, you could then use the Write to Spreadsheet File.vi to create a comma or tab separated file. The other option is to write the data straight to Excel using ActiveX. There's a shipping example that shows how that's done as well.

  • How to convert internal date to the format of user default setting

    In the BDC program, I need to convert the date, such as the sy-datum 20070427, to the format of user default that is defined in T-code SU01, such as YYYY-MM-DD or YYYY.MM.DD, and so on.
    The user format has 6 six kinds, and it is not good idea to write the code to process. So I look for the functions or CLASS method to process. I can use the function 'ITS_GET_USER_DEFAULTS' to get the user default setting of the Date format and Decimal notation.The problem is that I can not find the function or CLASS method to convert the internal date to user's date format.
    The function: CONVERT_DATE_TO_INTERNAL can not do it.
    The CLASS method: cl_abap_datfm=>conv_date_int_to_ext may be do it. But I do know how exchange the parameters, and fail to make it work finely.
    Is there the functions or CLASS method to process it?
    Thanks a lot!

    Hi John,
    create a veriable :
    data: v_date type char10.
    then after getting the date in YYYYMMDD format, write the following statement.
    WRITE SY-DATUM TO V_DATE.
    this might solve your problem.
    Regards,
    Hemant.

Maybe you are looking for

  • Ipod touch 1st generation won't play on ihome doc

    I have a 1st generation ipod touch, 32GB.  I received an iHome for Christmas last year that states it is compatible with the 1st generation ipod touch however when I put it in the cradle, it connects and disconnects over and over.  I looked and iTune

  • Queryview web service problem

    Hi, I'm still trying to get the queryview web service working.  When I call the service through Macromedia Flex I get a stream error and MS InfoPath gives me a" The SOAP response indicates that an error occurred: Authority check failed I'm fairly cer

  • Enhanced FlexWAN Module

    I have an Enhanced FlexWAN module in a 6509. I need to swap out one of the port adapters. What part of this is hot-swappable? Can the PA's be removed while the mod is in and switch on? Or is just the mod removable? Thanks in advance.

  • How to stop/disconnect USB device on OSX?

    How do I manually stop a USB device that I don't want the OS to recognize or run? On "About this Mac > More info" page, my Dell Axim X51v Pocket PC is listed as a USB device. I'm having problems using the Parallel Desktop running Windows XP to sync t

  • Have windows 8 with version adobe reader 10 and unable to watch hd videos

    unable to watch a hd video. have windows 8 with adobe reader 10 installed in the new machine