How to save Byte Array of raw data into JPEG image.

I have a image and I stored its data as byte array as
bimage = bitmap1.getRawData();
now I have Byte[] bimage, I want to save it as .jpeg image.
and show that image..............

the short way is this:
ImageIO.write(bimage, "jpeg", new File("image.jpg"));
Where you use the original Image object... but it has to be a java.awt.image.RenderedImage (which a java.awt.image.BufferedImage is). So this method would come in handy.
     public static BufferedImage getBufferedImage(Image img) {
          // if the image is already a BufferedImage, cast and return it
          if((img instanceof BufferedImage) && background == null) {
               return (BufferedImage)img;
          // otherwise, create a new BufferedImage and draw the original
          // image on it
          int w = img.getWidth(null);
          int h = img.getHeight(null);
          BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
          Graphics2D g2d = bi.createGraphics();
          g2d.drawImage(img, 0, 0, w, h, null);
          return bi;
     }If the byte array you have is raw image data, then you can look at the javax.imageio package and see what you can do with those classes.

Similar Messages

  • How to get byte array from jpg in resource for Image XObject?

    Does anyone know how to get an array of bytes from a jpg from resource without an external library except MFC?
    The array of bytes is needed to create an Image XObject so it can be included in an appearance for an annotation.

    Sounds like a standard Windows programming question, not specific to the SDK.

  • How to add byte[] array based Image to the SQL Server without using parameter

    how to add byte[] array based Image to the SQL Server without using parameter.I have a column in table with the type image in sql and i want to add image array to the sql image column like below:
    I want to add image (RESIM) to the procedur like shown above but sql accepts byte[] RESIMI like System.Drowing. I whant that  sql accepts byte [] array like sql  image type
    not using cmd.ParametersAdd() method
    here is Isle() method content

    SQL Server binary constants use a hexadecimal format:
    You'll have to build that string from a byte array yourself:
    byte[] bytes = ...
    StringBuilder builder = new StringBuilder("0x", 2 + bytes.Length * 2);
    foreach (var b in bytes)
    string binhex = builder.ToString();
    That said, what you're trying to do - not using parameters - is the wrong thing to do. Not only it is insecure due to the risk of SQL injection but in the case of binary data is also inefficient since these hex strings are larger than the original byte[]

  • How to save info in a meta-data of a jpg file?

    hi, i need to know how to save info in a meta-data of a jpg file:
    this is my code (doesn't work):
    i get an exception,
    javax.imageio.metadata.IIOInvalidTreeException: JPEGvariety and markerSequence nodes must be present
    at com.sun.imageio.plugins.jpeg.JPEGMetadata.mergeNativeTree(
    at com.sun.imageio.plugins.jpeg.JPEGMetadata.mergeTree(
    at playaround.Main.main(
    package playaround;
    import java.util.Iterator;
    import java.util.Locale;
    import javax.imageio.*;
    import javax.imageio.metadata.IIOMetadata;
    import javax.imageio.metadata.IIOMetadataNode;
    import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
    import org.w3c.dom.*;
    public class IIOMetaDataWriter {
    public static void run(String[] args) throws IOException{
    try {
    File f = new File("C:/images.jpg");
    ImageInputStream ios = ImageIO.createImageInputStream(f);
    Iterator readers = ImageIO.getImageReaders(ios);
    ImageReader reader = (ImageReader);
    ImageWriter writer = ImageIO.getImageWriter(reader);
    JPEGImageWriteParam param = new JPEGImageWriteParam(Locale.getDefault());
    IIOMetadata metaData = writer.getDefaultStreamMetadata(param);
    String MetadataFormatName = metaData.getNativeMetadataFormatName();
    IIOMetadataNode root = (IIOMetadataNode)metaData.getAsTree(MetadataFormatName);
    IIOMetadataNode markerSequence = getChildNode(root, "markerSequence");
    if (markerSequence == null) {
    markerSequence = new IIOMetadataNode("JPEGvariety");
    IIOMetadataNode jv = getChildNode(root, "JPEGvariety");
    if (jv == null) {
    jv = new IIOMetadataNode("JPEGvariety");
    IIOMetadataNode child = getChildNode(jv, "myNode");
    if (child == null) {
    child = new IIOMetadataNode("myNode");
    child.setAttribute("myAttName", "myAttValue");
    metaData.mergeTree(MetadataFormatName, root);
    catch (Throwable t){
    protected static IIOMetadataNode getChildNode(Node n, String name) {
    NodeList nodes = n.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
    Node child = nodes.item(i);
    if (name.equals(child.getNodeName())) {
    return (IIOMetadataNode)child;
    return null;
    static void displayMetadata(Node node, int level) {
    indent(level); // emit open tag
    System.out.print("<" + node.getNodeName());
    NamedNodeMap map = node.getAttributes();
    if (map != null) { // print attribute values
    int length = map.getLength();
    for (int i = 0; i < length; i++) {
    Node attr = map.item(i);
    System.out.print(" " + attr.getNodeName() +
    "=\"" + attr.getNodeValue() + "\"");
    Node child = node.getFirstChild();
    if (child != null) {
    System.out.println(">"); // close current tag
    while (child != null) { // emit child tags recursively
    displayMetadata(child, level + 1);
    child = child.getNextSibling();
    indent(level); // emit close tag
    System.out.println("</" + node.getNodeName() + ">");
    } else {
    static void indent(int level) {
    for (int i = 0; i < level; i++) {
    System.out.print(" ");

    Yes, you need store data to table, and fetch it when page is opened.
    Simple way is create table with few columns and e.g. with CLOB column and then create form based on that table.
    Then modify item types as you like, e.g. use HTML editor for CLOB column

  • Read image raw data without creating image

    Is there any way to read image raw data into an array from a file but not creating an image ? I looked through ImageIO. It seems that every time an image reader is called , a bufferediamge is created or reused ?
    Tanks fro any advice.

    Is there any way to read image raw data into an array from a file but not creating an image ? I looked through ImageIO. It seems that every time an image reader is called , a bufferediamge is created or reused ?
    Tanks fro any advice.

  • How to insert more than 32k xml data into oracle clob column

    how to insert more than 32k xml data into oracle clob column.
    xml data is coming from java front end
    if we cannot use clob than what are the different options available

    Are you facing any issue with my code?
    String lateral size error will come when you try to insert the full xml in string format.
    public static boolean writeCLOBData(String tableName, String id, String columnName, String strContents) throws DataAccessException{
      boolean isUpdated = true;
      Connection connection = null;
      try {
      connection = ConnectionManager.getConnection ();
      //connection.setAutoCommit ( false );
      PreparedStatement PREPARE_STATEMENT = null;
      String sqlQuery = "UPDATE " + tableName + " SET " + columnName + "  = ?  WHERE ID =" + id;
      PREPARE_STATEMENT = connection.prepareStatement ( sqlQuery );
      // converting string to reader stream
      Reader reader = new StringReader ( strContents );
      PREPARE_STATEMENT.setClob ( 1, reader );
      // return false after updating the clob data to DB
      isUpdated = PREPARE_STATEMENT.execute ();
      PREPARE_STATEMENT.close ();
      } catch ( SQLException e ) {
      e.printStackTrace ();
      return isUpdated;
    Try this JAVA code.

  • How To Save Screen Shot Photo From iPAD to JPEG FORMAT

    How To Save Screen Shot Photo From iPAD to JPEG FORMAT

    The "iPad format" is PNG (which is better quality than JPEG).
    There is no way to choose JPEG at the moment of taking the screen shot. You will need to convert the file using conversion software, probably on your computer. Google "convert PNG to JPEG".

  • How to save the music received in Whatsapp into iPhone?

    How to save the music received in Whatsapp into iPhone?

    This is not an iphone-specific problem. The person who sent you the files should have known that you cannot save them from WhatsApp person  on any smart phone
    Best help is to Contact whatsup support for iOS at  [email protected]
    I understand you think this is a Apple problem but Apple Haven't created this App

  • How can I pass a Presentation Variable (Date) into a prompt

    How can I pass a Presentation Variable (date) into a prompt? I seem to be able to do this successfully for a non-date value but have had no luck with a Date variable.
    Here's a simplistic version of what I'm trying to do:
    1. I have a Presentation Variable called startDate which is a Date that defaults to this SQL - SELECT "Reporting Dates"."Measure Date" FROM Trading WHERE "Reporting Dates"."Date Name" = 'Current'.
    2. I now want to pass this variable into a prompt with SQL like this: SELECT "Position Date"."Position Date" FROM Trading where "Position Date"."Position Date" = date'@{startDate}{2009-04-24}'
    I get this error: Datetime value @{startDate}{2009-04-24} from @{startDate}{2009-04-24} does not match the specified format.
    Now I can use the exact same syntax in a filter. For example, a simple Answers request where I pick Position Date with a filter saying "Position Date"."Position Date" = date'@{startDate}{2009-04-24}' works fine.
    What am I doing wrong?

    Can you provide more information please?
    1. What is the format of the first date prompt, is it YYYY-MM-DD or?
    2. Which data type is Position Date."Position Date" in the physical layer, date or date time?
    3. What is the column formula in the first prompt?
    4. The first prompt is set to drop-down or?
    5. If you are using this SQL Results in the second prompt:
    SELECT "Position Date"."Position Date" FROM Trading where "Position Date"."Position Date" = date '@{startDate}{2009-04-24}'
    then @{startDate} must be in YYYY-MM-DD format to work properly, otherwise (for example):
    datetime value 01/01/2000 from 01/01/2000 does not match the specified format.
    This doesn't work for example:
    SELECT Times.time_id FROM "Normal model" where Times.time_id =date '01/01/2000'

  • How do you convert Raw files into jpeg.

      I have never shot in Raw before and I have a huge project due tomorrow. I need help Asap. What is the easiest way to convert Raw files into jpeg, can Light Room convert the files. I have tried so many different ways and nothing seems to work.

    michaelfragale wrote:
      I have never shot in Raw before and I have a huge project due tomorrow. I need help Asap. What is the easiest way to convert Raw files into jpeg
    It depends on the sofware you have.  ACR (Adobe Camera Raw) hosted by Bridge or by Photoshop can convert ("open") raw files, as can Lightroom.
    However, not all camera models are supported by all versions of the software.  We need to know the make and exact model of the camera that generated the raw files to advice you further.
    We can also assist you with the conversion through ACR hosted by Photoshop.
    Olease note that there are dedicated forums for Lightroom, for Adobe Camera Raw and for Bridge.
    Here's the list of which cameras are supported by each version of ACR.  Note that later versions supporte all camera models supported in previous versions of ACR.
    Note that the latest version of ACR to run in CS4 is ACR 5.3;
    CS3 runs ACR 4.6;
    CS2 runs ACR 3.7;
    CS runs 2.4.

  • How do I convert a WHOLE PDF file into jpeg on LION?

    how do I convert a WHOLE PDF file into jpeg on LION?  I know how to open it in Preview but there is no longer an option through Print and if I export it only allows one page at a time and I need 223 pages...

    Use this Automator Action:

  • User selects a SWF and stuff data into an Image

    In my app user can upload an image, but if they select a SWF with FileReference, my code tries to stuff the data into an Image and in Internet Explorer screen goes black and IE hangs, Firefox just hangs.
    Any ideas?
    BTW, the SWF they upload might be corrupt.

    Mike. I've created a quick VI that may do want you want. The only problem arises when a pattern is rotated and you try to extract it. Since you can't build an image that isn't rectangular, I had to extract the rectangle that surrounds the pattern.
    Please let me know if you have any other questions.
    Kyle V
    Applications Engineer
    National Instruments
    Attachments: ‏1099 KB

  • How to pass byte array / binary data to a webservice as parameter in osb

    i have a webservice that has a byte array input parameter. i tried to use this WS in a message flow via service-callout. the problem i encountered is the following: since webservice call by using service-callout requires you to use an xml input as part of soap message, i insert both of $body/ctx:binary-content and $body/ctx:binary-content/@ref variables individually into this xml-message to pass binary-data to WS. When i debug the code, i see that it make calls to WS with $body/ctx:binary-content/@ref parameter, but the byte array passed is empty(not NULL)...
    note: i tried java-callut instead of service-called and used $body/ctx:binary-content as input parameter it worked. i think, this is because java-callout doesnt need an xml input and enable to take variables as is...
    can anybody help me to solve the problem with service-callout please?
    here is the input i use to call ws with service-callout method...
    <iso2Xml xmlns="">
    and this is my WS's signature:
    public String iso2Xml(byte[] request)

    See this thread
    /message/2187817#2187817 [original link is broken]
    Kind Regards

  • Save byte array (image) to file with servlet

    Good day.
    I should must to save a png image to file.
    I have a byte array of the image.
    This work is in a servlet.
    How can I do it?
    Best regards.
    Stefano Errani

    Good day.
    I have a byte[] and then I have used
    FileOutputStream fos = new FileOutputStream(getServletContext().getRealPath("/public_html/mcfoto/foto1.png"));
    fos.write(bt, 0, bt.length); // byte[] bt
    This on my web server that has public_html as root web directory.
    The server is in multi domain.
    In this mode I have an error.
    Then I have tryied to use
    FileOutputStream fos = new FileOutputStream("");
    FileOutputStream fos = new FileOutputStream(getServletContext().getRealPath(""));
    In both ways I have obtained an error.
    At last I have tryied in my localhost (local machine) using
    FileOutputStream fos = new FileOutputStream(getServletContext().getRealPath("/mcfoto/foto1.png"));
    All run correclty.
    The Application Server is Tomcat with Apache HTTP Server.
    The first server (of has Linux as OS.
    My local server has Windows as OS.
    I should want, if it's possible, an help.
    Best regards.
    Stefano Errani

  • How to send byte array and String values to servlet from Swing application

    Hi all,
    I am new to swing, servlet, and socket connection.
    I have swing application to draw images and some input data. I dont know to send to server.
    byte[] buf = baos.toByteArray();
    URL servletURL = new URL("
    URLConnection conn = servletURL.openConnection();
    BufferedWriter out = new BufferedWriter( new OutputStreamWriter( conn.getOutputStream() ) );
    can I do like this. Strings are received in server side perfect. but i cant get byte array data. Please help me.
    Thanks in advance.

    <img src="myservlet">
    In your myservlet:
    then write your image date via ImageIO that uses response output stream.

Maybe you are looking for

  • How to add Image in "SX_OBJECT_CONVERT_OTF_PDF" Function module

    Hi, We have scenario to add a BMP image from report to PDF format ,they are  using the SX_OBJECT_CONVERT_OTF_PDF function module to generate the report in PDF ,so we want to know how to add a image(BMP) for this function module or is there any other

  • Set the size of an ImageIcon

    Hi, I have dispalyed a picture on a JLabel using an ImageIcon. But I do not know how to set the height and width of the picture being displayed. Plz tell me how to control the size of the picture. Thanks a lot, Chamal.

  • Adobe Pro 9 CMap Error Message

    I am running Adobe Pro 9 and encountered the following error when trying to save a file to a newtwork drive: "The encoding (CMap) specified by a font is missing".  All the embedding options are set correctly.  I tried to install the Japanese font pac

  • Tutorial on Report Language(.rpt file)

    Can anyone send me any links or resources for understanding the report language of Oracle? from where I cud understand the syntax like - .define - .declare - #nc - #t - #s - .ifnull - .print - #dt - .set - .&[something] - .execute - #cl - .if - [char

  • What's going on with the products page in the website????

    Im trying to find accesories for my iphone and the website is not working... When i can see the products in the website??? neither in the US, ESPAñA website, why? what happen? when is fixed?