Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Forums Advisor I
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Compress Image Size

Hi

How to compress the image size before sending it to server??

Forums Advisor I
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Re: Compress Image Size

Isn't there any method by which we can compress the size of the image???

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Compress Image Size

Again you are a bit vague with your questions, some image formats are already compressed, which one in particular are you working with?

 

Take a look here as it may help you...

 

http://developer.blackberry.com/cascades/reference/bb__utility__imageconverter.html


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Forums Advisor I
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Re: Compress Image Size

Hey

The image that i want to send to server is of 12 Kb now what i want to compress it to 5 kb. Then,i have to add image convertor for this??

Suppose this is my code..

{

QString bound;
    QString crlf;
    QString data;
    QByteArray dataToSend;
    QFile file("uploadedfile");
    file.open(QIODevice::ReadOnly);

    bound = "---------------------------7d935033608e2";
    crlf = 0x0d;
    crlf += 0x0a;
    data = "--" + bound + crlf + "Content-Disposition: form-data; name=\"uploadedfile\"; ";
    data += "filename=\"background.png\"";

 

//here i should add the Image Convertor?
    data += crlf + "Content-Type: application/octet-stream" + crlf + crlf;
    dataToSend.insert(0,data);
    dataToSend.append(file.readAll());

    dataToSend.append(crlf + "--" + bound + "--" + crlf);

    QUrl url("link....");
    QNetworkRequest req(url);
    req.setHeader(QNetworkRequest::ContentTypeHeader, tr("multipart/form-data; boundary=") + bound);
    file.close();

}

Highlighted
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Compress Image Size

If your ByteArray really does hold a PNG (as your code suggests) then it is already compressed and any other compression you attempt will have little to no value.

 

PNG uses a lossless compression however so if you don't mind reducing the quality of the picture then converting it to a lossy format will certainly reduce the size, with jpg being the most common choice for this.

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.