BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/)
-   Developer Forum (http://www.blackberryforums.com/developer-forum/)
-   -   compression for images? (http://www.blackberryforums.com/developer-forum/186851-compression-images.html)

misty83 04-21-2009 02:31 AM

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

kind regards

pravin 04-21-2009 08:38 AM

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();
    }


misty83 04-22-2009 01:59 AM

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?


All times are GMT -5. The time now is 09:11 AM.

Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.