BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 04-21-2009, 02:31 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Jan 2009
Model: 7100T
PIN: N/A
Carrier: -
Posts: 73
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (permalink)
Knows Where the Search Button Is
 
pravin's Avatar
 
Join Date: Feb 2008
Model: 8130
PIN: N/A
Carrier: Sprint
Posts: 37
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (permalink)
Thumbs Must Hurt
 
Join Date: Jan 2009
Model: 7100T
PIN: N/A
Carrier: -
Posts: 73
Post Thanks: 0
Thanked 0 Times in 0 Posts
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


Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

HSS 10PCS VALVE SEAT & FACE CUTTER 45DEC 30DEC 20DEC FOR VINTAGE CAR, BIKES,JEEP
$153.0
HSS 10PCS VALVE SEAT & FACE CUTTER 45DEC 30DEC 20DEC FOR VINTAGE CAR, BIKES,JEEP picturevintage pressure gauge pat dec.20.1910 6 inch
$35.0
vintage pressure gauge pat dec.20.1910   6 inch picturePressure Guage, Antique, Vintage ASHCROFT. Dates Dec 1910. Steampunk, Altitude
$45.0
Pressure Guage, Antique, Vintage ASHCROFT. Dates Dec 1910. Steampunk, Altitude pictureHSS 21PCS VALVE SEAT & FACE CUTTER 45DEC 30DEC 20DEC FOR VINTAGE CAR,BIKES, JEEP
$226.99
HSS 21PCS VALVE SEAT & FACE CUTTER 45DEC 30DEC 20DEC FOR VINTAGE CAR,BIKES, JEEP pictureVINTAGE CENTURY SINGLE PHASE MOTOR 1/4 H.P. Type RS, PAT. DEC 1914
$130.0
VINTAGE CENTURY SINGLE PHASE MOTOR 1/4 H.P. Type RS, PAT. DEC 1914 picture






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