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: 147
Registered: ‎09-10-2008
My Device: Not Specified

Bitmap Loding Fail

Hi,

loading bitmap image but I can obtain only "Failed to load image"  any one tellme how to access the image in to our application.

 

 

private class ScrollingImageScreen extends MainScreen {
        private static final int HORZ_SCROLL_FACTOR    = 10;
        private static final int VERT_SCROLL_FACTOR    = 10;

       
         Bitmap bitmap = Bitmap.getBitmapResource("image.png");
        int left = 0;
        int top = 0;
        int maxLeft = 0;
        int maxTop = 0;
       
        public  ScrollingImageScreen() {
             
           
            if (bitmap == null) {
                UiApplication.getUiApplication().invokeLater(new Runnable() {
                    public void run() {
                        Dialog.alert("Failed to load image");
                        System.exit(0);
                    }
                });
                return;
            }
           
            if (bitmap.getWidth() > Graphics.getScreenWidth()) {
                maxLeft = bitmap.getWidth() - Graphics.getScreenWidth();
            }
           
            if (bitmap.getHeight() > Graphics.getScreenHeight()) {
                maxTop = bitmap.getHeight() - Graphics.getScreenHeight();
            }
        }
       
        protected void paint(Graphics graphics) {
            if (bitmap != null) {
                graphics.drawBitmap(0, 0, Graphics.getScreenWidth(), Graphics.getScreenHeight(),bitmap, left, top);
            }
        }
       
        protected boolean navigationMovement(int dx, int dy, int status, int time) {
            left += (dx * HORZ_SCROLL_FACTOR);
            top += (dy * VERT_SCROLL_FACTOR);

            if (left < 0) left = 0;
            if (top < 0) top = 0;
            if (left > maxLeft) left = maxLeft;
            if (top > maxTop) top = maxTop;

            invalidate();

            return true;
        }
       
    }

  ScrollingImageRecipe() {
        pushScreen(new ScrollingImageScreen());
    }
  public static void main(String[] args){
        ScrollingImageRecipe app = new ScrollingImageRecipe();
        app.enterEventDispatcher();
    }
  
    

Developer
Posts: 191
Registered: ‎04-03-2008
My Device: Bold 9700

Re: Bitmap Loding Fail

Hey, that code looks familiar.  :smileyhappy:

 

It looks ok; are you sure that "image.png" is being built into your application?

Developer
Posts: 147
Registered: ‎09-10-2008
My Device: Not Specified

Re: Bitmap Loding Fail

Yes the image is in the location but the image loading fail

 

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

Re: Bitmap Loding Fail

I agree with Richard that the most likely problem is the location of the image.  I suggest that you look at the *.jdp (project) file associated witht he project your are using (you can open it with notepad).  In there, you should chec the

 

[Files

 

section you should see your image and the ScrollingImageScreen.java class.  Here is an example:

 

[Files
..

com\mycompany\UI\BoldIcon.png
..
com\mycompany\UI\LoginScreen.java

..

]

 

In this case, the image file and the screen that uses it are both in the com/mycompany/UI directory.