09-08-2011 11:04 AM
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
Solved! Go to Solution.
09-08-2011 11:15 AM
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.
09-08-2011 12:12 PM - edited 09-08-2011 12:14 PM
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:
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.
09-08-2011 12:18 PM
@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.
09-08-2011 07:12 PM
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.
09-09-2011 02:13 AM - edited 09-09-2011 08:18 AM
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.
Yes It works well with set/getARGB