How Convert a Byte array to a image format

Hi,
How to convert a Byte array to an image format....I shall be more clear what i want...See i recieve a Byte array fom server this Byte array before recieveing at my end it was converted from an image/text format into a Byte array and is sent from server and, I recieve this Byte array now I have to convert this Byte array into their respective image....please tell me how to convert a Byte array to a image ......... Kindly explain clearly as i am new to Java......
Thanking You.

Note: This thread was originally posted in the [New To Java|http://forums.sun.com/forum.jspa?forumID=54] forum, but moved to this forum for closer topic alignment.

Similar Messages

  • 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:
    https://msdn.microsoft.com/en-us/library/ms179899.aspx
    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)
    builder.Append(b.ToString("X2"));
    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[]
    data.

  • How to send byte array of image with 300dpi.

    Hello fiends
                       i am making an application in which i have to send the byte array of an image with 300dpi.
    so i am using image snapshot class for that and use that code.
                        var snapshot:ImageSnapshot = ImageSnapshot.captureImage(cnvParent,300);
                        var bdata:String = ImageSnapshot.encodeImageAsBase64(snapshot);
    but when i send that bdata to php end using httpService.The size at other end of image increases surprisingly.i means it will increase its actual height and actual width.so is there any way to overcome this increase in size when i bitmapped image at 300 dpi?
    if there any way then please tell me.waiting for your reply.
    Thanks and Regards
        Vineet Osho

    Thanks david for such a quick reply.the link is really helpful.So we have to calculate the screendpi thruogh our code and then set the height and width of image.is there any simple way to sort out my problem.i just want to print my image at 300dpi but i am using image snapshot class so its taking the snap of my container(image) and save the image at 96 dpi which is dpi of my screen(monitor).so is there any way or any class in flex through which i got the image at its original dpi.i am not stick on 300 dpi but i m getting image from backend through xml at 300dpi.thats why i want the byte array i am sending should be at 300dpi.i am totally confused now.so please help me.
    Thanks and regards
      Vineet osho

  • Convertion of byte array in UTF-8 to GSM character set.

    I want to convert byte array in UTF-8 to GSM character set. Please advice How can I do that?

    String s = new String(byteArrayInUTF8,"utf-8");This will convert your byte array to a Java UNICODE UTF-16 encoded String on the assumption that the byte array represents characters encoded as utf-8.
    I don't understand what GSM characters are so someone else will have to help you with the second part.

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

    Hi,
    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 save Byte Array of raw data into JPEG image.

    Hello!
    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);
              g2d.dispose();
              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.

  • How can I convert OPENGL canvas graphics into bitmap image format.

    I used the following code... but no conversion made... plz tell the write way..
    public static void savePaintingJPG(GLCanvas canvas, String fileName) {
            // saves the content of the 'panel' in a file 'file'.jpg
            String name = "";
    int framewidth = canvas.getSize().width; // get the canvas' dimensions
    int frameheight = canvas.getSize().height;
    System.out.println(framewidth);
    System.out.println(frameheight);
      java.nio.ByteBuffer pixelsRGB = BufferUtils.newByteBuffer(framewidth * frameheight * 3); // create a ByteBuffer to hold the image data
    GL gl = canvas.getGL(); // acquire our GL Object
          // read the Frame back into our ByteBuffer
    gl.glReadBuffer(GL.GL_BACK);
    gl.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1);
    gl.glReadPixels(0, 0, framewidth, frameheight, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, pixelsRGB);
    int[] pixelInts = new int[framewidth * frameheight*3];       // Convert RGB bytes to ARGB ints with no transparency. Flip image vertically by reading the
         // rows of pixels in the byte buffer in reverse - (0,0) is at bottom left in OpenGL.
    int p = framewidth * frameheight * 3; // Points to first byte (red) in each row.
         int q;   // Index into ByteBuffer
      int i = 0;   // Index into target int[]
      int w3 = framewidth*3;    // Number of bytes in each row
      for (int row = 0; row < frameheight; row++) {
        p -= w3;
        q = p;
        for (int col = 0; col < framewidth; col++) {
          int iR = pixelsRGB.get(q++);
          int iG = pixelsRGB.get(q++);
          int iB = pixelsRGB.get(q++);
          pixelInts[i++] = 0xFF000000 | ((iR & 0x000000FF) << 16) | ((iG & 0x000000FF) << 8) | (iB & 0x000000FF);
            BufferedImage bimg = new BufferedImage(framewidth,frameheight,BufferedImage.TYPE_INT_ARGB);
              bimg.setRGB(0,0,framewidth, frameheight, pixelInts, 0, framewidth);
            try
                File imageFile = new File("final.jpg");
                File imagf = new File("final.png");
                File image = new File("final.bmp");
                ImageIO.write(bimg, "jpg", imageFile); // saves files
                ImageIO.write(bimg, "png", imagf);
                ImageIO.write(bimg, "bmp", image);
                   System.out.println("Success");
            catch (IOException e) {
                e.printStackTrace();
        }

    You want to convert it to an array of what? Of numbers? Of LabVIEW colors?
    The "Read BMP File.vi" VI outputs a 1-D array of the pixels, but I suspect it is not exactly in the format that you need. I am NOT sure, but I think that each group of 3 elements of that 1-D array (which is inside the cluster "image data" that the VI outputs) represents the red, green and blue levels of a single pixel (but it may be hue, saturation and lum.). Also, since it is a 1-D array, you would have to divide it by the width (which is also included in the "image data" cluster) to get some sort of 2-D array of data.
    You can find the "Read BMP File.vi" VI in the functions palete> "Graphics & sound">"Graphics Formats".

  • Byte array to png image conversion

    hi friends
    i am using a servlet using tomcat server to send multiple images to a client. i have stored all the images in a single byte array.and then encoded using base64. i am sending it to the client side and decoding it. when i extract the byte array and then try to convert it to image it shows an illegal argument exception.please help me?
    Pradeep

    dubwai
    Just looked at your code again. Did you mean int,not
    long?He wanted an unsigned int (which of course doesn't
    exist in Java) and if you look at his original code it
    was returning long.Well, it's not so much that I wanted an unsigned int, it's just that the data was stored as a 32 bit unsigned integer. Since the data represented numbers with a range of 0 to 2^32 - 1, the range exceeded what I could put in a Java int, thus I need to stuff it in a long - well, that was my reasoning anyway.
    Thanks for the nio tip, I'd not looked into that stuff and really should.
    Lee
    Thanks much for the code -

  • Converting a byte array into int

    Here's my problem, I've read my data from a server into a byte array.
    the array is 12 elements in length representing three int variables.
    int flag;
    int query_a;
    int query_b;
    here's what i receive:
    0 0 0 0 34 0 0 -2 21 0 0 0
    how do i convert these into the int values i need.
    i know the first four are for flag = 0, but how does it convert?
    0000 = 0 for each byte
    00000000 00000000 00000000 00000000 = 0 for each bit?
    or is there a method to convert from a byte to int?

    Look at the ByteBuffer class (part of 1.4.1) - before that, you would have had to manually build your integers using left shift and & operator (not that big of a deal, really).
    Be sure you know the "Endian"-ness of the platform you are reading data from though, otherwise, your ints will not be what you expect!
    - K

  • Converting a byte array or hex string  into DES key

    i required to covert a hex represented of DES key into key object for cryptography operation to performed ...
    can you help me to find out how to convert a hex representaion of key int DES key object

    hi friend,
    I think the key size is more than the required size. For DES algorithm, the key size is 64 bit long.But the code u have given has more than 64 bit, because of which this exception has been raised.
    Reduce the key value to 64bit and try. If it doesnt work,try the code given below .I think it might be helpful for u
    import javax.crypto.*;
    import javax.crypto.spec.*;
    public class Cryption
         public byte[] encrypt(byte[] keyData,byte[] clearMessage)
              try
                   SecretKeySpec sks = new SecretKeySpec(keyData,"DES");
                   Cipher c = Cipher.getInstance ("DES");
                   c.init(Cipher.ENCRYPT_MODE,sks);
                   byte[] encryptedMessage = c.doFinal(clearMessage);
                   return encryptedMessage;
              catch(Exception e)
                   e.printStackTrace();
              return null;
         public byte[] decrypt(byte[] keyData,byte[] cipherMessage)
              try
                   SecretKeySpec sks = new SecretKeySpec(keyData,"DES");
                   Cipher c = Cipher.getInstance ("DES");
                   c.init(Cipher.DECRYPT_MODE,sks);
                   byte[] decryptedMessage = c.doFinal(cipherMessage);
                   return decryptedMessage;
              catch(Exception e)
                   e.printStackTrace();
              return null;
         public static void main(String[] args)
              String keyString = "ABCDEF12";
              byte keyValue[] = keyString.getBytes();
              Cryption encryption = new Cryption();
              String Message = "Hello Welcome to world of Cryptography";
              System.out.println("Key Value (represented in HEX form): "+keyString);
              System.out.println("Key Value (represented in byte array form): "+keyValue);
              System.out.println("Original Message : "+Message);
              byte[] encryptedMessage = encryption.encrypt(keyValue,Message.getBytes());
              System.out.println("Encrypted Message : "+new String(encryptedMessage));
              Cryption decryption = new Cryption();
              byte[] decryptedMessage = decryption.decrypt(keyValue,encryptedMessage);
              System.out.println("Decrypted Message : "+new String(decryptedMessage));
    output :
    Key Value (represented in HEX form): ABCDEF12
    Key Value (represented in byte array form): [B@43c749
    Original Message : Hello Welcome to world of Cryptography
    Encrypted Message : "O3�?�M�,����������,�]�3�����R�?>C$
    Decrypted Message : Hello Welcome to world of Cryptography
    whenever u use any algorithm, first findout the key size or range that algorithm supports. It is very important
    regards,
    Deepa Raghuraman

  • 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("http://10.70.70.1:8080/servlet/SaveImage)
    URLConnection conn = servletURL.openConnection();
    conn.setDoOutput(true);
    BufferedWriter out = new BufferedWriter( new OutputStreamWriter( conn.getOutputStream() ) );
    out.write(buf&a=aaaa&b=bbbbb);
    out.flush();
    out.close();
    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:
    response.setContentType("image/jpeg");
    then write your image date via ImageIO that uses response output stream.

  • How to encrypt byte array with out padding using RSA in Java?

    I've modulus and public exponent as byte[] array, so I'm trying to convert into BigIntegers and then create public key and then Cipher. Here is the example code:
    With this I'm always getting different encrypted bytes, is it because of padding. I dont want to use any padding so what parameter I need to pass along with RSA? I've modulus byte[] array size 64 bytes. I believe I'll get 64 encrypted bytes. I've content size of 32 bytes to be encrypted.
    --------code begin ---------------------------
    BigInteger bexponent = new BigInteger(pubExpo);
    BigInteger bmodulus = new BigInteger(modulus);
    KeyFactory keyFactory = KeyFactory.getInstance("RSA");
    RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(bmodulus, bexponent);
    RSAPublicKey pubKey = (RSAPublicKey)keyFactory.generatePublic(pubKeySpec);
    Cipher c = Cipher.getInstance("RSA");
    c.init(Cipher.ENCRYPT_MODE, pubKey);
    return c.doFinal(content);
    --------code end---------------------------

    With this I'm always getting different encrypted
    bytes, is it because of padding. Yes, if you're using PKCS1Padding (which is the default in SunJCE if you don't specify it). Have a look at the PKCS1 spec if you haven't seen it already.
    http://www.rsasecurity.com/rsalabs/pkcs
    Section 7.2.1 talks about type 2 padding, which uses random bytes as the PS string.
    I dont want to use
    any padding so what parameter I need to pass along
    with RSA? NOPADDING. You should be able to find this out by look at the "Supported Paddings" parameter in your provider's database. Which of course, means you'll need to supply the right number of bytes to the Cipher.

  • 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="http://www.mycompany.com.tr">
    <request>{$body/ctx:binary-content/@ref}</request>
    </iso2Xml>
    and this is my WS's signature:
    @WebMethod
    public String iso2Xml(byte[] request)

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

  • How to change the bar chart rendering image format in SSRS

    Hello all,
    I am working with SQL Server 2008 R2 and I have a SSRS bar chart report, when the report got rendered over online or if the take Export (PDF and PPT), the image is in png format always, which is taking too much of time to execute the report in case of large
    data.
    Can, It be possible that the rendered image is in jpeg format instead of png.
    If Yes, please share the appropriate steps to follow:
    Thanks in advance
    Pankaj Kumar Yadav-

    Hi Pankaj067,
    According to your description, you want to change the bar chart rendering image format as JPEG format when previewing the report or exporting to a PDF file .
    In Reporting Services, the chart rendering image format is PNG by default. It’s a by-design behavior. And it doesn’t open any API for us to change the image type when exporting a chart to a format. So in your scenario, your requirement can’t be achieved
    in Reporting Services currently. I would recommend you submit a feature request to Microsoft at this site:
    https://connect.microsoft.com/SQLServer. So that we can try to modify and expand the product features based on your needs.
    If you have any question, please feel free to ask.
    Best regards,
    Qiuyun Yu
    Qiuyun Yu
    TechNet Community Support

  • How to download byte[] array, stored in database, as a file?

    We use Spring framework to develop our online system. Users now can upload their files. Data is stored in PostrgreSQL DB and associated with byte[] type attribute of a java class (through Hibernate). How can I perfom invert operation - transform a byte stream into a file and allow user to download it? Thanx

    public void writeToFile(byte[] b, String directory, String filename) throws IOException {
       File outputFile = new File(directory, filename);
       OutputStream outputStream = new FileOutputStream(outputFile);
       outputStream.write(b);
       outputStream.close();
    }

Maybe you are looking for

  • Purchase order and MIP selection

    Hi All, I have a requirement, please expalain whether it is possible or not in SAP? The Material is updated with the quality view and also have the MIP with diff.MICs. Say the effective date is 15.10.2010.So if the purchase order has been generated o

  • Transport rule doesn't work (trying to prepend a subject when mail comes to a second domain).

    This is an SBS2011 and accepts mail for two mail domains (successfully), but I am trying to phase out one of the two domains. I cannot find a better way to do it, but I have simply created this rule: priority 0 when a recipient's address contains '@<

  • CS6 Creative cloud updates could not be applied Win 7.

    I am trying to apply the latest updates to Creative Cloud CS6 on a computer running Win 7. The error log file gives this error:  Adobe Bridge CS6 5.0.1.1 Update There was an error installing this update. Please quit and try again later. Error Code: U

  • Custom field values are not storing in the data base

    Hi Friends, We have created one  Custom field called   ZZ_APPROVER in Rfx Header , we have included this field in the below  stuctures 1.INCL_EEW_PD_HEADER_CSF_BID 2.INCL_EEW_PD_HEADER_CSF The data type of this field ( ZZ_APPROVER ) is CHAR and the l

  • Smartforms Printing

    Hi Gurus, We have stuck with issue, we have created new Z-smartforms based on standard CRM_ORDER_CONFIRMATION_01. We have defined action for sending mail, mail is used new smartform which we defined in action conditons. once the action triggered we c