Reducing size of Image or byte array

Hello,
I am making a program where i have to send user's screen to another PC,
So I use class Robot to make a screen capture and send it via UDP.
However this is still too slow, my question is: is there some library to compress the size of byte array or Image?
Thanks for help,
Juraj

thanks for help i found it
byte[] input = ...;
// Create the compressor with highest level of compression
Deflater compressor = new Deflater();
compressor.setLevel(Deflater.BEST_COMPRESSION);
// Give the compressor the data to compress
compressor.setInput(input);
compressor.finish();

Similar Messages

  • Display image from byte array

    Hello Everybody,
    I need to display an image given in a byte array, how can I show this image in a JFrame?
    1. I tryied saving the image in a .jpg file,
         File file1 = new File("Path to my destination image");2. then I use a FileOutputStream to save the image in the path:
            FileOutputStream fos1 = new FileOutputStream(docu);
            fos1.write(ImageInbyteArray);
            fos1.close();3. Once I have the image in a file I'm trying to load it using a JButton, but the JButton doesn't display the image. I think that for some unknown (at least for me ;-) reason the file isn't still available to be used in the ImageIcon, this is my code:
            imgIconDocu = new ImageIcon("Path to my destination image");
            jBtnDocu = new JButton(imgIconDocu);What's wrong here?
    Thanks a lot

    Does the byte array contain a JPEG image? Where did
    you get the contents of the byte array?yes the array contains the JPEG image, I have a database in PostgreSQL, and the images are stored in blob in the database. I have to call a service in the server and in return it gives me the 3 images as byte arrays, that's the reason I only have the byte arrays. so I tryed saving the images as jpeg files in my hard disk to show them, but it appears that they are not available to show them in Swing after saving them. I can only show the images if I close my application and start it again :-(
    I tryed flushing and closing the FileOutputStream after the writting process (fos.write(bytearrayImage);
    fos.flush();
    fos.close();)
    Y also tryed:
    fos.write(bytearrayImage);
    fos.close();
    fos.flush();But it doesn't work either :-(
    What do you recommend me?.
    Thanks a lot,
    Johnny G L

  • How to reduce size of image without loss quality

    I am website developer design a website http://www.ritikakaur.com/ in wordpress php i am new in photoshop and i want to use some image plz suggest me how can i reduce size of image without loss of image quality.

    Which file formats are eligible for your purposes?
    non-destructive compression has limits, so you may have to compromise.

  • How to reduce size of image in Selection Screen

    Hi all
    I am trying to add an image in Selection screen and i want to reduce size of image .
    Please help me asap.
    Thanks & Regards
    Shaveta

    Hi Prashat
    I tried by reducing the size of container , But scroll bars appears automatically .
    The size of Picture remains same .
    Please tell me if there is any option to fix the size of container ... so that picture reduces its size automatically .
    Thanks & Regards
    Shaveta

  • Converting image into byte array

    Hi all,
    How to convert an integer array image into byte array ?
    here i have a image like this :
    private static int pixelArray[] = {
    0xff000000, 0xff000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    0xff000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000
    From this one i create image like this one :
    Image image = Image.createRGBImage(pixelArray, width, height, true);
    Now i want to convert that pixelArray into byte array ? how to do this
    additionally i want to send this byte array to servlet .
    thanks in advance.

    Hi,
    If you want to convert your int array to a byte array you should
    split each integer into 4 bytes to avoid losing information. You can
    rebuild your integer array later if you need to. I think this code
    will work (i havent tested it):
    byte[] pixel= new byte[pixelArray.length<< 2];
    for (int i= pixelArray.length- 1; i>= 0; i--) {
      int aux= i<< 2;  // i* 4 = i<< 2
      pixel[aux]=    (byte) (pixelArray>> 32);
    pixel[aux+ 1]= (byte) (pixelArray[i]>>> 16);
    pixel[aux+ 2]= (byte) (pixelArray[i]>>> 8);
    pixel[aux+ 3]= (byte) pixelArray[i];
    Greets.

  • How to reduce size of image while uploading it in livecycle pdf.

    Hi,
    I have created a pdf with Image field using live cycle designer.
    I have selected "Sizing: Scale Image to fit Rectangle".
    Now the problem is the pdf which i have created is 1.5MB and if i import or upload a 2.5MB image in image field then the size of pdf becomes 6MB.
    I have around 20 image fields in my pdf report , so if people keep uploading high resolution images in the pdf then the pdf becomes more then 15MB, slow and unmanagable.
    Is there any way by which even if I upload a 5MB image the it should automatically reduce image size?
    As the users does not bother to reduce the size of image they just upload high resolution and large size image in pdf.
    Please tell me the way through which i can reduce the image size automatically while uploading.
    Regards,
    Kartik Shrivastava

    Hi Prashat
    I tried by reducing the size of container , But scroll bars appears automatically .
    The size of Picture remains same .
    Please tell me if there is any option to fix the size of container ... so that picture reduces its size automatically .
    Thanks & Regards
    Shaveta

  • Create image from byte[]array on server side

    Hello everyone..
    I'm developing an application which will take snapshots from a mobile device, and send it to my pc via bluetooth. I have my own midlet which uses the phone camera to take the snapshot, i want to transfer that snapshot to my pc.
    The snapshot is taken is stored in an array byte.
    The image can be created on the phone itself with no problem using : image.createImage(byte[])
    my problem is that when i send the array byte via bluetooth, and receive it on the server, i cannot create the image using the :image.createImage() code
    The connection is good since i have tested by writing the content of the array in a text file.
    Piece of midlet code:
                try{
                     stream = (StreamConnection)Connector.open(url);
                     OutputStream ggt = stream.openOutputStream();
                     ggt.write(str);
                     ggt.close();
                }catch(Exception e){
                     err1  = e.getMessage();
                }where str is my array byte containing the snapshot
    And on my server side:
    Thread th = new Thread(){
                   public void run(){
                        try{
                             while(true){
                                  byte[] b = new byte[in.read()];
                                  int x=0;
                                  System.out.println("reading");
                                  r = in.read(b,0,b.length);
                                  if (r!=0){
                                       System.out.println(r);     
                                       img = Image.createImage(b, 0, r);
                                                            //other codes
                                       i get this error message:
    Exception in thread "Thread-0" java.lang.UnsatisfiedLinkError: javax.microedition.lcdui.ImmutableImage.decodeImage([BII)V
         at javax.microedition.lcdui.ImmutableImage.decodeImage(Native Method)
         at javax.microedition.lcdui.ImmutableImage.<init>(Image.java:906)
         at javax.microedition.lcdui.Image.createImage(Image.java:367)
         at picserv2$1.run(picserv2.java:70)
    Please anyone can help me here? is this the way to create the image on the server side? thx a lot

    here is exactly how i did it :
    while(true){
                                  byte[] b = new byte[in.read()];
                                  System.out.println("reading");
                                  r = in.read(b, 0, b.length);
                                  if (r!=0){
                                       Toolkit toolkit = Toolkit.getDefaultToolkit();
                                       Image img = toolkit.createImage(b, 0, b.length);
                                       JLabel label = new JLabel(new ImageIcon(img) );
                                       BufferedImage bImage = new BufferedImage(img.getWidth(label),img.getHeight(label),BufferedImage.TYPE_INT_RGB);
                                       bImage.createGraphics().drawImage(img, 0,0,null);
                                       File xd = new File("D:/file.jpg");
                                       ImageIO.write(bImage, "jpg", xd);
                                       System.out.println("image sent");
                             }Edited by: jin_a on Mar 22, 2008 9:58 AM

  • What is the best way to get an image as byte array

    Hi, I have an iamge stored in a file (jpg or gif) and I want to get the pixels as byte array. The image will be black and white only (tresholded) so byte will be enough to hold all the colors. What I'm doing now works but it just doesn't look good so I think there must be a better way.
    Thanks!

    just in case somebody else tries to do the same. When
    you first get the jpg image with the JPEG decoder and
    store it in a BufferedImage you can't get the pixel
    samples as byte arrays. You'll have to get them first
    as int[] and then make your own byte[].Anything coming in as pixels tends to be highly organized. You have this image array right. Now, how is it organized you must ask yourself? Then you can access it, bytewise or bitwise!

  • Converting Image to Byte Array and then to String

    Hi All...
    Can anyone please help me. I have got a problem while converting a Byte array of BufferedImage to String.
    This is my code, First i convert a BufferedImage to a byte array using ImageIO.wirte
    public String dirName="C:\\image";
    ByteArrayOutputStream baos=new ByteArrayOutputStream(1000);
    BufferedImage img=ImageIO.read(new File(dirName,"red.jpg"));
    ImageIO.write(img, "jpg", baos);
    baos.flush();
    byte[] resultimage=baos.toByteArray();
    baos.close();
    Then i tried to convert this byte array to a string
    String str=new String(resultimage);
    byte[] b=str.getBytes();
    This much worked fine. But when i reversed this process to re-create the image from that string. i found the image distroted.
    BufferedImage imag=ImageIO.read(new ByteArrayInputStream(b));
    ImageIO.write(imag, "jpg", new File(dirName,"snap.jpg"));
    I got this snap.jpg as distroted.
    Please help me i have to convert the image to a string and again i have to re-create the image from that string.

    To conver the bytearray to string use base64.encoding
    String base64String= Base64.encode(baos.toByteArray());
    To convert back use Base64.decode;
    byte[] bytearray = Base64.decode(base64String);
    BufferedImage imag=ImageIO.read(bytearray);

  • Conversion of image into byte array

    I have a problem in converting .png image into bytestream, if anyone can help in this pls do so.....

    Hi,
    To convert an Image to bytes you can use the Image.getRGB() method.
    http://java.sun.com/javame/reference/apis/jsr118/javax/microedition/lcdui/Image.html#getRGB(int[], int, int, int, int, int, int)
    -Henrik

  • How do I reduce size of image/document that I am emailing

    How do I reduce size of document emailing

    The only way is to compress it into a ZIP or similar file.

  • Image to byte array

    hello,
    how can i get an image in jar file as a byte[] or can i convert an image to byte[]?
    thx...

    To read a bytes from a jar file, use a JarInputStream. If you're just trying to read bytes from a jar, it doesn't make any difference whether it's an image or not.
    To get the bytes from an Image, you need to put more information in your question - are you talking about an image file, like a JPEG or TIFF? What do you want to do with it? Or are you talking about an Image object in Java? If so, which specific concrete subclass, and what do you want to do with it?

  • How to reduce size of images in Aperture ?

    My situation, lots of pics, most ~5mb in size, most now do not need that high a quality, and in need of reducing disk space usage. Is there an application or a technique within Aperture, that will allow me to select images and then have those images reduced in size, say from 5mb to 2.5mb?
    Thanks for any assist.

    Well if those images are not important and it is unlikely you would want to do anything other than look at them, then why not grab an external drive and relocate the masters there and leave them at home.
    That way you free up space but still have the generated previews in the library to take with you. You can control the quality of the previews in the preferences and then force Aperture to generate the previews again from the masters with the new settings by selecting the photos in question in the browser and holding the option key after bringing up the context menu.
    Combined with ratings for example, you could then make low-res, highly compressed previews for the unrated photos, go back and change the preferences and make progressively higher quality previews for the higher rated photos, culminating in full-res, high quality previews for the 5 star photos.
    That's the way I'd do it.

  • Propoportionally reduce size of image

    The help file says:
    To preserve the element's proportions (its width-to-height
    ratio) as you adjust its dimensions, Shift-drag the corner
    selection handle.
    When I SHIFT on the corner selection the HAND appears and not
    the size change icon...what gives or doesn't give?
    ALSO...I don't see the resize button on the properties:
    Click the Reset size button in the image Property inspector.
    Thanks, --bill

    Bill,
    > When I SHIFT on the corner selection the HAND
    > appears and not the size change icon...what gives
    > or doesn't give?
    That sounds like you're hitting the space bar, rather than
    shift. Are
    you saying you have the Free Transform Tool engaged on a
    shape or symbol,
    and you're hitting shift -- and *that's* when you see the
    hand?
    David
    stiller (at) quip (dot) net
    Dev essays:
    http://www.quip.net/blog/
    "Luck is the residue of good design."

  • How to reduce size of image from original size

    hi,
    I want to draw an image in particular width and height, for example that image has original size (300,300) but i want some time that image in (200,200) size and some time that image should draw in (100,100) size . how to do this ??
    Actually when i draw that image in small area that large one image it draw as overlapped the remaing with and height of image in that small area..
    pls , help me

    hi,
    i guess scaling will help. if i remember correctly, the java tutorial contains details of scaling.
    good luck
    ======
    Kiran

Maybe you are looking for

  • Payment to vendor thru Petty cash

    Dear all While making a payment to vendor thru petty cash by deducting TDS amount total payment amount should not add that TDS amount but in our case total payment is considering that  TDS amount also. Earliest help is needed. Viral.

  • Changing data in 'hidden' fields through BSP

    Hi all, We are using custom copy of hap_document BSP and in there i am trying to change values in the appraisal document using application->doc. I am able to change the values for the fields that are displayed in the layout in the application->doc-t_

  • Nice design: A bunch of calendar appointments that are impossible to delete

    Where I used to work, we had an iCal server through which people could schedule meetings. Those appointments got synced to my phone. I don't work there anymore, and I've deleted the "work" calendar off my system and synced. But my phone is still full

  • SQL Server 2012 Express LocalDB parm for keeping unicode char

    in developer's windows 8.1 pc, the SQL Server 2012 Express LocalDB does not seem to keep Unicode like \U2221. it get translated to the plain - instead of keeping as −. what  parameter od I need to setup to make sure it keep such character as is

  • Why can't I get my Nook books anymore?

    I can no longer open my Nook books or add new ones.  What's going on?