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
New Contributor
Posts: 2
Registered: ‎04-04-2012
My Device: developer
My Carrier: developer

Issues with bitmaps. Fast on SO6 and very slow on SO7

Hi,

 

I have a BitmapField matrix of 128 elements.
screen displayed on 8x16.

To BitmapsField array assigned different
scaled bitmaps (25 diferents)
when programmed time elapses or
when the user moves trackpad
or when user touch the screen

the problem is
If I run the code on a device with OS 6.
working properly.
but if I run it on a device with OS 7.
slowly draw the bitmaps on the screen.

I did many tests and I read many forum topics
I am sure that is slow to assign bitmaps to
BitmapField

Somebody help me please

 

public class GameScreen extends MainScreen implements MyInterface, Runnable
{
    private BitmapField[][] bitmapfields = new BitmapField[8][16];
    private Bitmap bitmap1, bitmapScaled1, bitmap2, bitmapScaled2, bitmap3, bitmapScaled3;
    private int i, j;
    
    public GameScreen()
    {
        // Scaled Bitmaps.
        // Sample 3 bitmaps but my proyect is 25 diferent bitmaps
        bitmap1 = Bitmap.getBitmapResource("img_house.png");
        bitmapScaled1 = new Bitmap(30, 30);
        bitmap1.scaleInto(bitmapScaled1, Bitmap.FILTER_LANCZOS);
        
        bitmap2 = Bitmap.getBitmapResource("img_dog.png");
        bitmapScaled2 = new Bitmap(30, 30);
         bitmap2.scaleInto(bitmapScaled2, Bitmap.FILTER_LANCZOS);
        
         bitmap3 = Bitmap.getBitmapResource("img_tree.png");
         bitmapScaled3 = new Bitmap(30, 30);
        bitmap3.scaleInto(bitmapScaled3, Bitmap.FILTER_LANCZOS);
        
        // BitmapFields Array. 128 elements in a matrix 16x8.
        // To show on mainScreen
        for(i=0; i<8; i++)
            for(j=0; j<16; j++)
                bitmapfields[i][j] = new BitmapField();
                
    }

    public void run()
    {
        while(_run)
        {
            try {
               Thread.sleep(45);

               for(i=0; i<8; i++)
                    for(j=0; j<16; j++)
                    {
                        // Change bitmaps on a bitmapFields when time passes
                        // or when the user moves on trackpad or tap screen
                        switch(_color)
                        {
                        case 1:
                        bitmapfields[i][j].setBitmap(bitmapScaled1); break;
                        case 2:
                        bitmapfields[i][j].setBitmap(bitmapScaled2); break;
                        case 3:
                        bitmapfields[i][j].setBitmap(bitmapScaled3); break;
                        }
                    }
            } catch (InterruptedException e) { e.printStackTrace(); }
        }
    }
    
    // Here I have implemented navigationMovement
    // and more...
}

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

Re: Issues with bitmaps. Fast on SO6 and very slow on SO7

Welcome to the forums.

 

Interesting problem, it doesn't make sense does it. 

 

I don't see it anywhere, but I presume that you add the bitmapfields to the screen at some stage.  How do you add them?

 

Are you seeing this performance issue on the Simulator or just on the device?

 

I am not aware of a performance issue with assigning a Bitmap to a BitmapField.  The biggest issue I have in terms of performance is converting the file to a Bitmap.

 

New Contributor
Posts: 2
Registered: ‎04-04-2012
My Device: developer
My Carrier: developer

Re: Issues with bitmaps. Fast on SO6 and very slow on SO7

// I add the bitmapfields to the screen

// 16 horizontalFiledManager with 8 bitmapfield each

 

private VerticalFieldManager vfm = new VerticalFieldManager(Field.USE_ALL_WIDTH);
private HorizontalFieldManager[] hfmanagers = new HorizontalFieldManager[16];

 

public GameScreen()

{

    :

    :

    :

 

    for(j=0; j<16; j++)
            {
                 for(i=0; i<8; i++)
                {
                    bitmapfields[i][j] = new BitmapField();
                    hfmanagers[j].add(bitmapfields[i][j]);
                }
                vfm.add(hfmanagers[j]);
           }
        add(vfm);

}

 

I seeing this performance issue on the Simulator and on the Device.

As in the simulator operates in the device
the only difference is that the simulator is even a bit slower.

 

I used simulator and device model 9900 and 9850 (so7)

and simulator and device model 9300 and 9700 (so6)

 

i have two weeks trying that works

 

i read on page that download SDK7 about use Canvas on SO7.
I trying with canvas. Work so slow too.

 

Help please.

 

 

 

 

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

Re: Issues with bitmaps. Fast on SO6 and very slow on SO7

Couple of things I note:

 

Thread.sleep(45);

 

This suggests you are expecting a full screen refresh every 45 milliseconds.  As I understand, in OS 6.0 devices, a full screen bitmap paint takes of the order of 100 milliseconds and in OS 7.0 if is significantly faster but I suspect that 45 milliseconds is really pushing it.  Can you optimize the processing in any way, for example, skip the update if the color has not changed?  Or extend the BitmapField so that it remembers the bitmap that it has, and if you 'set' the same bitmap it ignores the request.  Then the screen will only be updated when needed, which will significantly improve things I suspect.

 

In this regard, the major difference between OS 7.0 and OS 6.0 devices is the color.  OS 7.0 uses a full 32 bit color, OS 6 and before use effectively 16 bit color.  You might like to try your processing with very simple images, just single colors, and see if this improves performance. 

 

Just one clarification.  You say the processing is slow.  can you explain what that means to the person playing the game?  What happens slowly?