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


NEW Appion MGAVCT 1/4 Inches MegaFlow Vacuum-Rated Valve Core Removal Tool picture

NEW Appion MGAVCT 1/4 Inches MegaFlow Vacuum-Rated Valve Core Removal Tool

$55.00



Blue  2.5L Vacuum Cleaner, Lightweight Vac for Carpets and Hard Floors picture

Blue 2.5L Vacuum Cleaner, Lightweight Vac for Carpets and Hard Floors

$64.00



Appion MGAVCT 1/4 Inches MegaFlow Vacuum-Rated Valve Core Removal Tool picture

Appion MGAVCT 1/4 Inches MegaFlow Vacuum-Rated Valve Core Removal Tool

$65.08



Impress GoVac Handheld Cordless Rechargeable Vacuum Cleaner With Charging Base; picture

Impress GoVac Handheld Cordless Rechargeable Vacuum Cleaner With Charging Base;

$36.98



VacPouch Premium Chamber Vacuum Pouches, Heavy Duty 4mil, PACK OF 500 picture

VacPouch Premium Chamber Vacuum Pouches, Heavy Duty 4mil, PACK OF 500

$77.92



VEVOR 5 Gallon Vacuum Chamber with 5CFM Vacuum Pump Kit 1/3HP Single Stage 110V picture

VEVOR 5 Gallon Vacuum Chamber with 5CFM Vacuum Pump Kit 1/3HP Single Stage 110V

$92.49







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