[Solved] Display BitMap

Put your problem here if it does not fit any of the other categories.

[Solved] Display BitMap

Postby mauri » Mon Jan 21, 2008 1:18 pm

Hi all



Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class bitmaptest extends Activity {
  3.  
  4.         /** Called when the activity is first created. */
  5.  
  6.     @Override
  7.  
  8.     public void onCreate(Bundle icicle) {
  9.  
  10.         super.onCreate(icicle);
  11.  
  12.         AbsoluteLayout absLayout = new AbsoluteLayout(this);
  13.  
  14.         Bitmap bitMap = BitmapFactory.decode("/res/drawable/google_logo_plain.png");
  15.  
  16.         BitmapDrawable bmd = new BitmapDrawable(bitMap);
  17.  
  18.        
  19.  
  20.         ImageView imageView = new ImageView(this);
  21.  
  22.         imageView.setBackground(bmd);
  23.  
  24.         //imageView.setImageResource(R.drawable.google_logo_plain);
  25.  
  26.      
  27.  
  28.         imageView.setScaleType(ScaleType.CENTER);
  29.  
  30.         absLayout.addView(imageView,
  31.  
  32.                 new AbsoluteLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 0, 0)
  33.  
  34.         );
  35.  
  36.        
  37.  
  38.         setContentView(absLayout);
  39.  
  40.     }
  41.  
  42. }
  43.  
  44.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


when i run this code, it displays a blank sceen
but if i try with

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. imageView.setImageResource(R.drawable.google_logo_plain);
  3.  
  4.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


the image will be displayed
what im doing wrong?

mauri
User avatar
mauri
Junior Developer
Junior Developer
 
Posts: 13
Joined: Tue Dec 04, 2007 7:14 pm

Top

Postby mauri » Mon Jan 21, 2008 2:44 pm

got it!

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class bitmaptest extends Activity {
  3.  
  4.     @Override
  5.  
  6.     public void onCreate(Bundle icicle) {
  7.  
  8.         super.onCreate(icicle);
  9.  
  10.         AbsoluteLayout absLayout = new AbsoluteLayout(this);
  11.  
  12.         Bitmap bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.google_logo_plain);
  13.  
  14.         BitmapDrawable bmd = new BitmapDrawable(bitMap);
  15.  
  16.        
  17.  
  18.         ImageView imageView = new ImageView(this);
  19.  
  20.         imageView.setImageDrawable(bmd);
  21.  
  22.      
  23.  
  24.         imageView.setScaleType(ScaleType.CENTER);
  25.  
  26.         absLayout.addView(imageView,
  27.  
  28.                 new AbsoluteLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 0, 0)
  29.  
  30.         );
  31.  
  32.        
  33.  
  34.         setContentView(absLayout);
  35.  
  36.        
  37.  
  38.     }
  39.  
  40. }
  41.  
  42.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


the BitMap must be loaded by:


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Bitmap bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.google_logo_plain);
  3.  
  4.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
User avatar
mauri
Junior Developer
Junior Developer
 
Posts: 13
Joined: Tue Dec 04, 2007 7:14 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 7 guests