Problem loading bitmap from file (still unresolved)

Problems with Canvas, OpenGL, etc...

Problem loading bitmap from file (still unresolved)

Postby SolidSora » Tue Nov 09, 2010 5:52 am

I'm trying to load a bitmap from file.

Here is the code where I declare it:
Code: Select all
private final String path = "C:\\Users\\Public\\Documents\\TestScroller\\groundpiece.gif";
   private Bitmap groundPiecePic = BitmapFactory.decodeFile(path);


Here is where I try to draw it:
Code: Select all
   public void draw(Canvas c){
      c.drawBitmap(groundPiecePic, getX(), getY(), groundPiecePaint);
      Log.d("GroundPiece", "drawn");
   }


This is causing my program to crash the way it is now. What is wrong?
SolidSora
Junior Developer
Junior Developer
 
Posts: 24
Joined: Tue Oct 12, 2010 12:56 am

Top

Re: Problem loading bitmap from file (still unresolved)

Postby SolidSora » Wed Nov 10, 2010 2:11 am

please help
SolidSora
Junior Developer
Junior Developer
 
Posts: 24
Joined: Tue Oct 12, 2010 12:56 am

Re: Problem loading bitmap from file (still unresolved)

Postby pmduque » Tue Nov 16, 2010 2:53 pm

Do you have a stack trace from the crash? Probably the file is too big for you device memory (it happened to me), so you will need to use the inSampleSize in order to manage memory consumption...
pmduque
Freshman
Freshman
 
Posts: 5
Joined: Tue Nov 16, 2010 2:40 pm

Re: Problem loading bitmap from file (still unresolved)

Postby moblcade.com » Tue Nov 16, 2010 7:19 pm

You're coding for an Android device which will have no access to the files on your computer. As you can see, you're trying to load a bitmap stored in your computer's file system. You can only load bitmaps from assets, resources, or the Android file system. You might be able to load them using HTTP, but I've never tried it.

You'll have to put your image in the "assets" directory within your project. Then you can load your bitmap with the AssetManager:

If you put a png image in your project so that its path is "assets/images/myimage.png" you would load it as follows:

Code: Select all
Bitmap bmp = BitmapFactory.decodeStream(myActivity.getAssets().open("images/myimage.png");
moblcade.com
Junior Developer
Junior Developer
 
Posts: 19
Joined: Tue Sep 07, 2010 6:31 pm

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest