BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 04-21-2009, 02:31 AM   #1
misty83
Thumbs Must Hurt
 
Join Date: Jan 2009
Model: 7100T
PIN: N/A
Carrier: -
Posts: 73
Default compression for images?

Please Login to Remove!

are there any methods or is it possible somehow to set a compression to the encodedImage (jpg/png)?

kind regards
Offline  
Old 04-21-2009, 08:38 AM   #2
pravin
Knows Where the Search Button Is
 
pravin's Avatar
 
Join Date: Feb 2008
Model: 8130
PIN: N/A
Carrier: Sprint
Posts: 37
Default

Try this -

Code:
/**
     * Uncompress a previously compressed string;
     * this method is the inverse of the compress method.
     * @param byte array containing compressed data
     * @return uncompressed string
     * @throws IOException if the inflation fails
     */
    public static final byte[] uncompress(final byte[] compressed) throws IOException {
//        String uncompressed = "";
        byte[] result = null;
        try {
            ByteArrayInputStream bais = new ByteArrayInputStream(compressed);
            GZIPInputStream zis = new GZIPInputStream(bais);

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            int numBytesRead = 0;
            byte[] tempBytes = new byte[DEFAULT_BUFFER_SIZE];
            while ((numBytesRead = zis.read(tempBytes, 0, tempBytes.length)) != -1) {
                baos.write(tempBytes, 0, numBytesRead);
            }

            result = (baos.toByteArray());
        } catch (Exception e) {
            System.out.println("Error while unzip " + e.toString());
        }

        return result;
    }





/**
     * Compress a string
     * @param uncompressed string
     * @return byte array containing compressed data
     * @throws IOException if the deflation fails
     */
    public static final byte[] compress(final byte[] uncompressed) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        GZIPOutputStream zos = new GZIPOutputStream(baos);

        byte[] uncompressedBytes = uncompressed;

        zos.write(uncompressedBytes, 0, uncompressedBytes.length);
        zos.close();

        return baos.toByteArray();
    }
Offline  
Old 04-22-2009, 01:59 AM   #3
misty83
Thumbs Must Hurt
 
Join Date: Jan 2009
Model: 7100T
PIN: N/A
Carrier: -
Posts: 73
Default

i was asking rather about image compression Image compression - Wikipedia, the free encyclopedia

i do not need anything to be zipped and then unzipped. actually i even cannot do that. cause the idea is to make image compression so that it will be smaller, then send it to the server. i do not want to do pack-unpack. cause on the server side i cannot unpack anything. anyway, that is not the idea. You presented the code to pack-unpack, not the real image compression.
anyway, thanks i think Your code maybe usefull for me in the future.

kind regards.

ps.
anyone knows smth about image compression in bb?
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


128K RAM - APPLE - ORIGINAL APPLE prototype BOARD picture

128K RAM - APPLE - ORIGINAL APPLE prototype BOARD

$408.75



APPLE 630-0895-B  VRAM 128K X 8 BOARD CARD VINTAGE picture

APPLE 630-0895-B VRAM 128K X 8 BOARD CARD VINTAGE

$74.77



APPLE 820-0522-A 630-0895-B LITE VRAM 128K X 8 BOARD  picture

APPLE 820-0522-A 630-0895-B LITE VRAM 128K X 8 BOARD

$149.99







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.