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
dx22
Posts: 402
Registered: ‎11-26-2010
My Device: Torch
Accepted Solution

How to resize Bitmap

I have a bitmap with lets say size 200x100 and I want to create a bitmap with size 200x200 and the first bitmap to be drawn into the new one and have 50px offset from the top and bottom of the new bitmap?

 

How can I do that and be compatible with OS >= 4.6. I see that in OS 5.0 we have a scaleInto method in the Bitmap class - http://www.blackberry.com/developers/docs/5.0.0api/ 

----------------------------------------------------------------------
Press the button to give kudos if I helped you :smileyhappy:
Please use plain text.
Developer
YamilBracho
Posts: 713
Registered: ‎05-31-2010
My Device: 8520
My Carrier: Movistar

Re: How to resize Bitmap

Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to resize Bitmap

Actually very easy in this case where you have equal sizes, so no scaling required..  I don't have time to create code atm, so here is a quick suggested way and I hope you can take it from there.

 

Create the new Bitmap, the size you want.

Create a Graphics context using that Bitmap

paint the old Bitmap onto the new Graphics context (drawBitmap) in the correct place.

 

Good luck

Please use plain text.
Developer
mreed
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: How to resize Bitmap

[ Edited ]

In your other post you mentioned that you wanted to rotate the bitmap.. I'm guessing that is why you want the NxN sized bitmap. You might want to also look into the ImageManipulator class. It is available for download:

http://supportforums.blackberry.com/t5/Java-Development/Rotate-and-scale-bitmaps/ta-p/492524

 

It will let you rotate and paint the bitmap onto another graphics object without having to create a new bitmap and have the white background issue that you would get from doing it yourself manually.

Please use plain text.
Developer
dx22
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: How to resize Bitmap

@peter By creating graphics context do you mean something like this:

 

Bitmap b = new Bitmap(width, height);
Graphics g = Graphics.create(b);
g.drawBimap(...);
...

 

If yes then this approach does not work because when the bitmap has bigger size(1024x768) the Graphics object can't be created and IllegalArgumentException is thrown.This works for smaller images only.

----------------------------------------------------------------------
Press the button to give kudos if I helped you :smileyhappy:
Please use plain text.
Developer
amrishodiq
Posts: 112
Registered: ‎09-23-2009
My Device: Not Specified

Re: How to resize Bitmap

Yes, this way the obstacle is Blackberry's Graphic's buffer which is available only two times the size of the screen.

 

Another option is to get Bitmap's RGB and than put the right RGB into the correct place int this new Bitmap.

Please use plain text.
Developer
dx22
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: How to resize Bitmap

[ Edited ]

Yes thats what I was thinking but I was wondering whether it will be possible to put the RGB data into the correct place. I will try it today.

 

 

UPDATE:

Yes It works well with set/getARGB

----------------------------------------------------------------------
Press the button to give kudos if I helped you :smileyhappy:
Please use plain text.