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
Posts: 42
Registered: ‎03-03-2009
My Device: 9600
My Carrier: Vodafone

Rotate EncodedImage Object or BitmapField Object.

Hi,

          Can anyone give me the codesnipet for rotete the EncodedImage with 90 degree.   I don't want code to rotate the Bitmap because it's give me "OutOfMemory Error" while converting EncodedImage to Bitmap Image.

 

           Other wise , you can provide me the exact code to rotate BitmapField itself.

 

Thanks In Advance,

Tej

 

Tejas Barbhaya

Logistic Infotech
tej.barbhaya@gmail.com
www.logisticinfotech.com
Developer
Posts: 467
Registered: ‎07-16-2009
My Device: Z10 LE
My Carrier: Vodafone NL

Re: Rotate EncodedImage Object or BitmapField Object.

Here is just example how to operate bitmap argb data.

 

Bitmap original;
int[] argb = new int[original.getWidth() * original.getHeight()];
original.getARGB(argb, 0, original.getWidth(), 0, 0, original.getWidth(), original.getHeight());


 Bitmap newBitmap = new Bitmap(original.getHeight(), original.getWidth());
int[] newArgb = new int[original.getWidth() * original.getHeight()];

for (int i=0; i < original.getHeight(); i++)

 for (int j =0; j< original.getWidth();j++)

 newArgb[i][j] = argb[j][i];

newBitmap.setArgb(newArgb, 0, original.getHeight(), 0, 0, original.getHeight(), original.getWidth());

 

Thanks,

Eugen

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Rotate EncodedImage Object or BitmapField Object.

Unfortunately Eugens approach requires that you create a Bitmap first so will also suffer from OutOfmemory.

 

However even if you do manage to rotate the image, you can't display it until you create a Bitmap anyway, so I suggest that you just create a scaled Bitmap of the appropriate size, and then rotate it.

 

Why won't this work for you?

Developer
Posts: 222
Registered: ‎11-11-2009
My Device: Storm

Re: Rotate EncodedImage Object or BitmapField Object.

@Peter "I suggest that you just create a scaled Bitmap of the appropriate size" - can you please explain about your suggestion in detail, which i was not aware

 

Thanks in  advance

with regards,
Vignesh J

-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Don't forget to mark your post as solved if you get the answer and dont forget to give kudos if the answer is useful for you.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Developer
Posts: 467
Registered: ‎07-16-2009
My Device: Z10 LE
My Carrier: Vodafone NL

Re: Rotate EncodedImage Object or BitmapField Object.

Peter's suggestion - scale bitmap to appropriate width and height when allocating of width*height int array won't trigger OutOfMemoryException.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Rotate EncodedImage Object or BitmapField Object.

@zany - See the API documentation for

 

Bitmap.createBitmapFromBytes(...., scale);

 

I think there are improved methods in OS 5.0 and in fact OS 5.0 may provide a way to rotate an encoded image too.

Developer
Posts: 222
Registered: ‎11-11-2009
My Device: Storm

Re: Rotate EncodedImage Object or BitmapField Object.

Thank you Peter. I will go through them especially OS 5.0

with regards,
Vignesh J

-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Don't forget to mark your post as solved if you get the answer and dont forget to give kudos if the answer is useful for you.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Rotate EncodedImage Object or BitmapField Object.

Unless I missed something I don't remeber seeing (I just read through a bunch of classes in the documentation) any way to draw a rotated image using the 5.0 API. You need to do it manually.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Rotate EncodedImage Object or BitmapField Object.

@rcmaniac25 - I think you are right, just had a quick look myself and couldn't find anything.  Loads of new Scale methods though.

 

Have you seen this?

http://supportforums.blackberry.com/t5/Java-Development/Bitmap-rotation-with-drawTexturedPath/m-p/36...

Developer
Posts: 222
Registered: ‎11-11-2009
My Device: Storm

Re: Rotate EncodedImage Object or BitmapField Object.

@Peter - sample code which is in the link what you have given will work fine. Only thing for me in that code is about the x, y position what we are passing to drawRotatedBitmap method. We have to calculate them based on the width, height of the image, and angle we are going to rotate the image. If we are going rotate the image in 90, 180, 270 360 degrees, then it will be easy to calculate x, y position. If we are going rotate the image around 145 degree, then it will hard to calculate x, y position.

with regards,
Vignesh J

-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Don't forget to mark your post as solved if you get the answer and dont forget to give kudos if the answer is useful for you.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------