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
redpath
Posts: 62
Registered: ‎07-29-2008
My Device: Not Specified

Bitmap editing

Trying to change the color of a BlackBerry Bitmap. I can get this to work for MIDP Image type

but will start to use EncodedImage. So whats wrong with this?

basically get the ARGB and set my color. The color does not change for the new image

 I assume getBitmap makes a copy. I see noway to create a EncodedImage from a Bitmap?

So a little help here.

 

  static private EncodedImage colorImage(EncodedImage image, int color){
        int[] rgbData= new int[image.getWidth()*image.getHeight()];
        Bitmap bm= image.getBitmap();

        bm.getARGB(rgbData,
                     0,
                     image.getWidth(),
                     0,
                     0,
                     image.getWidth(),
                     image.getHeight());
System.out.println(image.getWidth()*image.getHeight());

        for (int i=0; i<rgbData.length; i++)
            rgbData[i]= (rgbData[i]&0xFF000000)| color;
        bm.setARGB(rgbData,0, image.getWidth(),0,0,image.getWidth(),image.getHeight());
        return image;
    }

BlackBerry Development Advisor
MSohm
Posts: 14,757
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Bitmap editing

The Bitmap bm you are modifying is a stand alone copy of the image.  Changing it does not affect EncodedImage image.

 

Returning bm should provide you with your modified image.  There are no APIs in the BlackBerry API set that allow you to convert a Bitmap to an Encoded image, however a solution to this has been posted in this thread:

 

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=736&query.id=1057...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker