Bitmap.getBitmapResource bug?

Hello

I try to use Bitmap.getBitmapResource and it cannot read the file.

I tested this code

DataInputStream din = new DataInputStream(this.getClass().getResourceAsStream(fileName));
byte[] buff1 = new byte[din.available()];
din.readFully(buff1);
Bitmap bitmap1 = Bitmap.createBitmapFromPNG(buff1, 0, buff1.length);
System.out.println("Bitmap from buffer: "+bitmap1);

Bitmap bitmap2 = Bitmap.getBitmapResource(fileName);
System.out.println("Bitmap from resource: "+bitmap2);

and the output is:

Bitmap of the buffer: net.rim.device.api.system.Bitmap@37152698

CAFETERIA: could not find /8000_100%bitmapfont.png

Bitmap from resource: null

is this a known problem or am I missing something?

Thank you

Guy

To summarize, what you're saying, is that the same "filename" provides valid data when you read using

Class.getResourceAsStream (),

but fails when you use it in

Bitmap.getBitmapResource (fileName);

I think the problem is the main "/" is necessary for the first method, but not for the second.  Give a try to test this:

Bitmap bitmap2 = Bitmap.getBitmapResource (fileName.substring (1));

Tags: BlackBerry Developers

Similar Questions

  • Why not Bitmap.GetBitmapResource)

    I am trying to load a bitmap and I get an IllegalArgumentException in JDE 5.0.0 (have not compiled with previous can).  The file exists in the project, in fact, it is even used for the transfer of the icon of the Application - that work spendidly.  I created the image in Adobe Illustrator and exported as a 100 x 75 pixels format PNG-24. I realized another PNG this way that exists in the project who is responsible (for the unfolded above).  I tried to produce another image and load, with the two images previous (one that works and one that doesn't work) in the project and it fails with this defense, too.

    No restrictions on the inclusion of images in projects?

    Thank you

    Brandon

    The simple code:

    final Bitmap bm1 = Bitmap.getBitmapResource("cameraRollover.png");
    

    The call stack:

    Thread [StarfaceRecoApp(230)id=321742848] (Suspended (exception IllegalArgumentException))
        Resource.getIconOffset(byte[], int) line: 158
        Resource.getIconBytes(byte[], int) line: 188
        StarfaceRecoAppRIMResources(Resource).findResource(String) line: 63
        StarfaceRecoAppRIMResources(Resource).getResource(String) line: 103
        Bitmap.getBitmapResource(String, String) line: 2333
        Bitmap.getBitmapResource(String) line: 2359
        MainHubScreen.(StarfaceApp$StarfaceRecoApp) line: 30
        StarfaceApp$StarfaceRecoApp.() line: 187
        StarfaceApp$StarfaceRecoApp.main(String[]) line: 27
    

    Hello

    I don't know, but have you tried to do something like that?

    PNGEncodedImage.getEncodedImageResource("cameraRollover.png").getBitmap()
    

    Since it is a PNG image.

  • How to access image stored in Blackberry using Bitmap.getBitmapResource ()?

    I want to access an image stored in Blackberry, say instead of "store/home/user/image.png".

    Now I can access the image as,

    String filePath = "file:///store/home/user/image.png;
    Bitmap image = Bitmap.getBitmapResource(filePath);
    BitmapField bitmapField = new BitmapField(image, BitmapField.FOCUSABLE);
    

    OR

    I have to access

    String filePath = "file:///store/home/user/image.png;
      FileConnection fconn = (FileConnection)Connector.open(filePath, Connector.READ);
      if (fconn.exists())
      {
                    ........
                    ........                           
    
         input.close();
         fconn.close();                            
    
      }
    

    I am able to access the image using the second way, but I want to know that can I access using 'Bitmap.getBitmapResource (filePath)?

    None

  • Eclipse plugin 1.0.0.67 problems with Bitmap.getBitmapResource

    I upgraded to 1.0.0.67, and now Bitmap.getBitmapResource is unable to find the png files. Everything else on the project seems to be the same. Any ideas what's happening here?

    Fixed by getting the latest pack of component for 4.7

  • Bitmap.getBitmapResource (...) does not find my file?

    Hi all, I'm a 1st year student at the University of Warwick (United Kingdom) and I'm writing a small application for the Blackberry Storm, but I can't get my code to use just...

    Bitmap image = Bitmap.getBitmapResource ("c.gif");

    BitmapField bField = new BitmapField (image, BitmapField.FOCUSABLE);

    Add (bField);

    if(image == null) {Add (new RichTextField ("zero!")) ;}

    ^^ the snippet above is what I wrote, as far as I can see it is all very well, and the c.gif file is in the same directory as the source .java code when I Isaiah to compile the project (in the RIM JDE)

    When I run my app in the Simulator, rather than the displayed image, I just get "null!" printed...

    I don't know I'm just something dumb/obvious but I tried to move the .gif to different folders, but I can't make it work

    Thanks for reading this,

    Harri

    You have added the file to the project?

  • Malfunction Bitmap.getBitmapResource

    I have an image in the res project folder and load the bitmap as the background of the screen with Bitmap.getBitmapResource ("pic.png").

    On a device, it works and finds the image in the res folder, but on another device, it will return null and can't seem to find the «pic.png» When I put the pic.png in the res and the src folder, it works on both devices.

    No idea why this is happening?

    It seems to be resolved when I place the files in a subfolder of the folder res for example folder named img and then access it with the img/pic.png path. The problem seems to be that in the root folder.

    Thanks anyway

  • jpg does not with: img Bitmap = Bitmap.getBitmapResource ("img2.jpg");


    Sorry, the file has not been added to the project.  I'm new to programming of BB.

    It is very good.

  • Beginner: OutOfMemory Error when resizing Bitmap

    I get OutOfMemory error when I tried to get the bitmap off EncodedImage

    backgroundBitmap = Bitmap.getBitmapResource ("bitmap.png")

    image = PNGEncodedImage.Encode (backgroundBitmap);
    image = image.scaleImage32 (Display.GetWidth (), Display.getHeight ());
    _backgroundBitmap = image.getBitmap ();

    the red line causes this problem, can someone help me out on this please? is there another method I can try to achieve the same result?

    Thank you...

    Hello

    you use scaleImage32 the wrong way, try this that method or rather. You can also resize bitmap image without code it first.

    Kind regards

    Piotr

  • How to access an image button (bitmap image)?

    Hello

    I have two questions.

    1 .i have over the path navigationClick() method, but always attack don't know, how to get the id of the clicked field?

    2. How can I put a label with this bitmapField?

    Here is my code.

    Image bitmap myBitmap = Bitmap.getBitmapResource ("Order.jpg");
    BitmapField myBitmapField = new BitmapField (myBitmap, BitmapField.FOCUSABLE);
        
                
    Image bitmap deliverBitmap = Bitmap.getBitmapResource ("Deliver.jpg");
    BitmapField deliverBitmapField = new BitmapField (deliverBitmap, BitmapField.FOCUSABLE);

    protected boolean navigationClick (int status, int time)
    {
    System.out.println ("key =" + status);
        
    Returns true;
    }

    No, I mean that you set your variables of the bitmap to the screen, not only in its constructor.

    Focus on the ground = getLeafFieldWithFocus();

    If (focus.equals (bitmapfield1) {;} doStuff () else if...})

  • How to dynamically set the width of the bitmap as mobile size and adjust accordingly the photo.

    I have the bitmap image. Now, I want the bitmap to the screen but its size should be as mobile width and adjust the picture accordingly. For the former I enlarge it should look like small small mobile screen.

    My code but its not working.

    public static BitmapField getHeader() throws NullPointerException {}
    Bitmap b = Bitmap.getBitmapResource("img/logo.jpg");
    return (new BitmapField (b, Field.FIELD_HCENTER) {})
    Protected Sub layout (int width, int height) {}
    setExtent (365, 80);
    }
    });
    }

    You will need to put the image yourself to match the dimensions you need.

    Watch Bitmap.scaleInto)

    If you have transparent images, then watch this:

    http://supportforums.BlackBerry.com/T5/Java-development/resizing-transparent-bitmaps/Ta-p/703239

  • custom bitmaps field not change image when click on

    I created a custom bitmap field and I change the image on the center of my field of custom bitmaps and unfocus

    but when I implement the method of navigation click to change the image when you click on this image does not change...

    my custom bitmap field filed only to focus or unfocus on the image does not change my field of custom bitmaps.

    Bitmap onfocus = Bitmap.getBitmapResource("111.png");
                    Bitmap onunfocus = Bitmap.getBitmapResource("666.png");
                    mybutton1 = new CustomBitmapField(0,"",onunfocus,onfocus,Field.FOCUSABLE){
                         protected boolean navigationClick(int status, int time) {
    
                             mybutton1.setBitmap(Bitmap.getBitmapResource("favu.png"));
    
                             return true;
    
                         }
    
                    };
    add(mybutton1);
    

    and my class of field customBitmap is

    public class CustomBitmapField extends BitmapField {
    
        Bitmap Unfocus_img, Focus_img, current_pic;
        int width;
        String text;
        Font font; 
    
        public CustomBitmapField(int width, String text, Bitmap onFocus, Bitmap onUnfocus, long style) {
            // TODO Auto-generated constructor stub
            super();
            Unfocus_img = onUnfocus;
            Focus_img = onFocus;
            current_pic = onFocus;
            this.text = text;
            this.width = width;
    
        }
        protected void layout(int width, int height)
        {
            setExtent(current_pic.getWidth(), current_pic.getHeight());
        }
        protected void paint(Graphics graphics)
        {
            /*try
            {
                    FontFamily fntFamily = FontFamily.forName("BBAlpha Sans");
                    font = fntFamily.getFont(Font.BOLD,14);
            }
            catch(Exception e)
            {
                font = Font.getDefault();
    
            }
            graphics.setFont(font);
            graphics.setColor(Color.WHITE); */
            graphics.drawBitmap(0, 0, current_pic.getWidth(), current_pic.getHeight(), current_pic, 0, 0);
    
            //graphics.drawText(text, width, 7);
        }
        protected void onFocus(int direction)
        {
            super.onFocus(direction);
            current_pic = Unfocus_img;
    
            this.invalidate();
        }
      protected void drawFocus(Graphics graphics, boolean on)
      {
    
        }
        protected void onUnfocus()
        {
            super.onUnfocus();
            current_pic = Focus_img;
            invalidate();
        }
        public boolean isFocusable() {
            return true;
        }
        protected boolean navigationClick(int status, int time) {
    
            fieldChangeNotify(0);
            return true;
        }
    
    }
    

    When you debug this code, which of your methods of navigationClick, is actually used?

    When you expect the bitmap change, the code should lead object so that to happen.  Paint running?  This is the correct Bitmap painting?

    If you answer these questions, I think that you figure to yourself what is the problem.

    While you're there, you can also watch the following Threads that you have started or contributed to.  Can you solve or continue to contribute to these?

    http://supportforums.BlackBerry.com/T5/Java-development/gif-animation-not-displaying-properlly/m-p/2...

    http://supportforums.BlackBerry.com/T5/Java-development/timepicker-issue/m-p/2387819

    http://supportforums.BlackBerry.com/T5/Java-development/ListField-focus-color-problem/m-p/2407881#m2...

  • Bitmap class: how to use the directories under the directory res/img?

    I have the following image resources structure.

    RES/img

    I added two subdirectories of img, hi_res and low_res, so my resource structure looks like:

    RES/img/hi_res

    RES/img/low_res

    When I create a Bitmap object, I want to use a PNG image under hi_res such as:

    Bitmap bg = Bitmap.getBitmapResource("hi_res/cool.png");
    

    However, I return the following error in the Console:

    [0,0] CAFETERIA: could not find hi_res/cool.png

    I tried the structure of the whole package such as img/hi_res/cool.png and who fired a similar error. How to properly use packages in the res directory?

    Well done.

  • Can I scale to bitmap or bitmapField?

    Image bitmap bitmap = Bitmap.getBitmapResource (fileName);
    BitmapField bitmapField = new BitmapField (bitmap, BitmapField.FIELD_HCENTER);

    I have Bittmap and I need scale it... can you hel me please?

    You can find a lot of discussion about it by typing 'ladder' in the search box, give it a try.
    first train: http://supportforums.blackberry.com/t5/Java-Development/Rotate-and-scale-bitmaps/ta-p/492524

    Also, check the int http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/system/EncodedImage.html#scale... )

  • Field bitmap button

    Hello...

    Yes, I looked in other posts.  And trying to disect the sample APP CustomButton.  But, the image does not change the focus for this, and really, I had a hard time to work with it.

    So, after several hours, I write...

    I would like to make my button below clickable so that it plays a sound image and changes on focus.  However, I have not yet found a strategy that I could implement.

    Can someone provide some guidance?  The error that I get with the implementation ŒUVRE FieldChangeListener when I try to extend the UiApplication is that...

    ....... The SmartCord type must implement the inherited abstract method FieldChangeListener.fieldChanged (field, int)

    So clearly something is wrong and I have a bad strategy, but I have no idea what.

    I use absolute available to resize the image according to the size of the screen

    Thanks for the tips...

    package com.package;
    
    import net.rim.device.api.ui.*;
    import net.rim.device.api.ui.component.*;
    import net.rim.device.api.ui.container.*;
    import net.rim.device.api.system.*;
    
    /**
     * This class extends the UiApplication class, providing a
     * graphical user interface.
     */
    
    public class MyApp extends UiApplication implements FieldChangeListener
    {
    
        public static void main(String[] args)
        {
                MyApp theApp = new MyApp();
                theApp.enterEventDispatcher();
        }
    
        public MyApp()
        {
            MainScreen mainScreen = new MainScreen();
            AbsoluteFieldManager MainFieldManager = new AbsoluteFieldManager(){
    
                //Size the Field to the Screen Size
    
                protected void sublayout( int maxWidth, int maxHeight)
                {
                int width = Display.getWidth();
                int height = Display.getHeight();
                super.sublayout( width, height);
                setExtent( width, height);
                     }
    
                //Override the paint method to draw the background image.
    
                public void paint(Graphics graphics)
                {
                    Bitmap background = Bitmap.getBitmapResource("background.png");
                    Bitmap backgroundscaled = new Bitmap(Display.getWidth(),Display.getHeight());
                    backgroundscaled = new Bitmap(Display.getWidth(),Display.getHeight());
                    background.scaleInto(backgroundscaled, Bitmap.FILTER_BILINEAR, Bitmap.SCALE_TO_FILL);                                   
    
                    //Draw the background image and then call paint.
    
                    graphics.drawBitmap(0, 0, Display.getWidth(), Display.getHeight(), backgroundscaled, 0, 0);
                    super.paint(graphics);
                }
            };                        
    
            //Power Button 
    
            Bitmap powerbutton = Bitmap.getBitmapResource("blackbutton.png");
            Bitmap whitepowerbutton = Bitmap.getBitmapResource("whitebutton.png");
            Bitmap powerscaled = new Bitmap(Display.getWidth()/2,Display.getWidth()/2);
            powerscaled = new Bitmap(Display.getWidth()/2,Display.getWidth()/2);
            Bitmap powerpressedscaled = new Bitmap(Display.getWidth()/2,Display.getWidth()/2);
            powerpressedscaled = new Bitmap(Display.getWidth()/2,Display.getWidth()/2);
            powerbutton.scaleInto(powerscaled, Bitmap.FILTER_BILINEAR, Bitmap.SCALE_TO_FILL);
            whitepowerbutton.scaleInto(powerpressedscaled, Bitmap.FILTER_BILINEAR, Bitmap.SCALE_TO_FILL);
            BitmapField bitmapField2 = new BitmapField(powerscaled, Field.FOCUSABLE) ;
            //Location
            int field2x=Display.getWidth()/4;
            int field2y=(Display.getHeight()/2)-(Display.getWidth()/4);   
    
            //Add the manager to the screen.
    
            mainScreen.add(MainFieldManager);
    
            //Add the fields to the manager.
    
            MainFieldManager.add(bitmapField2,field2x,field2y);            
    
            //Push the screen.
    
            pushScreen(mainScreen);
        }
    }
    

    Thanks for the reply.

    Yes, I am just now simply show the domains I've created for the package which is currently running and which displays some things I'd like to that.

    So my queestion is, what do you suggest to be the next?  I feel that I need to have separate classes for each button, which extends to a BitmapField?  I left it because I didn't know how to add.

    Thank you

  • get the Bitmap Image of the web site or remote location

    Hi, yesterday I asked for some ease of image horizontal scorlling with blackberry. It's work very well. Thank you for all.

    But I could not do my job. What I need, that I have to get the Image from a web site (not in the project of ths) and display it in the BB device. I can do this and I get byte array and show the image using BitmapField. But this installation of scrolling does not work with the bitmap field.

    Is is them possible to get my web site dynamic images of the Bitmap object?

    Here is the code that you sent me.

    // ------------------------------------------

    package com.falseflag.blackberry.recipes;

    Import net.rim.device.api.system.Bitmap;
    Import net.rim.device.api.ui.Graphics;
    Import net.rim.device.api.ui.UiApplication;
    Import net.rim.device.api.ui.component.Dialog;
    Import net.rim.device.api.ui.container.MainScreen;

    class ScrollingImageRecipe extends UiApplication {}

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

    Bitmap bitmap;
    int left = 0;
    high int = 0;
    int maxLeft = 0;
    maxTop int = 0;
           
    public ScrollingImageScreen() {}
    bitmap image = Bitmap.getBitmapResource ("test.png");
           
    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, int time status) {}
    left += (dx * HORZ_SCROLL_FACTOR);
    top += (dy * VERT_SCROLL_FACTOR);

    If (on the left< 0)="" left="">
    If (upper-< 0)="" top="">
    If (left > maxLeft) left = maxLeft;
    If (top > maxTop) top = maxTop;

    Invalidate();

    Returns true;
    }
    }

    Public Shared Sub main (String [] args) {}
    ScrollingImageRecipe app = new ScrollingImageRecipe();
    app.enterEventDispatcher ();
    }
       
    {ScrollingImageRecipe()}
    pushScreen (new ScrollingImageScreen());
    }

    }

    //-------------------------------

    Please be so kind to give me a solution for this issue.

    You can use a browserfield to display web content in your application.  Take a look at the browserfielddemo provided with the BlackBerry JDE for example

    If you ask how to connect to a web site, please see the httpdemo.

    This example shows how to create a scrolling image field.

    -Creates a scrolling Image field
    Article number: DB-00681

    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800345/...

Maybe you are looking for

  • Firefox latest version (7.0.1) is detected as obsolete

    Each time that a website tries to detect which version of Firefox that I use, he seems to believe that I use an older version. The thing is, I always have to keep it up to date. Feedback from Mozilla even tool at input.mozilla.com says: "Oh!" So, you

  • Compatible battery for Satellite Pro A10

    I have a portable Satellite Pro A10 and the battery reaches the end of its useful life and requires replacement. The model number is PA3284U-1BRS is DC10.8V 3600mAh. The current site has no record of such a device is the compatible battery? Thanks in

  • No sound on itunes

    I am running OSX 10.11.3 with iTunes 12.3.2.35 My Music mp3 and m4a files wouldn't play on iTunes. It shows that if a file is read, but there is no sound. The same files play fine on Quick Time player... Any ideas?

  • How can I use keywords (such as Viagra, *, etc.) to filter spam

    Shippers use random letters that are allowed to pass through my JUNK screening setting.  I would like to take a step further, using frequent key words in their "offers". emails go straight to DELETE it so I don't have to (everyday!) perform a SCAN, b

  • I need wireless driver for hp 2300-p6-desktop pc

    I need to find drivers for hp p6-2300 Wireless Desktop pc. I tried at hp, but they do not have the drivers listed.