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

Java Development

Reply
Developer
GoldenJoe
Posts: 342
Registered: ‎09-28-2009
My Device: Not Specified

Re: upload resized image.

When encoding.  I'm attempting to resize a jpeg taken with the Torch's 5MP camera.  First, I load it as an EncodedImage, resize the EncodedImage, then attempt to encode the byte data.

Please use plain text.
Developer
daniloercoli
Posts: 49
Registered: ‎05-06-2009
My Device: Not Specified

Re: upload resized image.

Hi,

 

i'm using the Jpeg Encoder you should find within the BB SDK in this way:

 

 

try { 

EncodedImage originalImage = EncodedImage.createEncodedImage(data, 0, -1);

//starting resize
EncodedImage bestFit2 = resizeEncodedImage(originalImage, width, height);
originalImage = null;
Bitmap resizedBitmap = bestFit2.getBitmap();
bestFit2 = null;

//encoding 
try {
	Log.trace("starting resizing to jpg format ");
	imageBytes = JPEGEncodedImage.encode(resizedBitmap, 75).getData();
} catch (Exception e) {
	Log.error(e, "Error during JPEG encoding, restore prev img");
	imageBytes = data;
}

} catch (Error  err) { //capturing the JVM error. 
       Log.error(err, "Error while resizing");
	throw new IOException("Sorry, we are unable to resize your images");
}
			

 

Considerer that  when using "big" images  this code can throw "out of memory error"

 

 

Please use plain text.
Developer
GoldenJoe
Posts: 342
Registered: ‎09-28-2009
My Device: Not Specified

Re: upload resized image.

Bummer.  That's more or less what I was doing.  I guess I won't be encoding as JPEG in this particular instance.  Fortunately, the PNG solution a few posts back works in the same case, so it's an option for anyone else running into memory issues.

Please use plain text.