copyWindowBitmap()

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

copyWindowBitmap()

Postby rm123 » Wed Jan 30, 2008 8:03 pm

I am trying to use copyWindowBitmap() but the created bitmap does not display.


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     @Override
  2.  
  3.     public void onCreate(Bundle icicle)
  4.  
  5.     {
  6.  
  7.         super.onCreate(icicle);
  8.  
  9.         setContentView(R.layout.main);
  10.  
  11.         TableLayout table1 = (TableLayout)findViewById(R.id.table1);
  12.  
  13.         ImageView image1 = (ImageView)findViewById(R.id.image1);
  14.  
  15.         ImageView image2 = (ImageView)findViewById(R.id.image2);
  16.  
  17.         image1.setImageResource(R.drawable.icon);
  18.  
  19.         Bitmap bmp = table1.copyWindowBitmap();
  20.  
  21.         image2.setImageBitmap(bmp);
  22.  
  23.     }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
rm123
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Jan 30, 2008 5:09 pm

Top

Postby plusminus » Thu Jan 31, 2008 12:44 am

Hello rm123,

read the SDK carefully (also had to read it twice):
Bitmap android.view.View.copyWindowBitmap()

public Bitmap copyWindowBitmap()
Return a copy of the bitmap holding the overall contents of the window this view is attached to. If the view is not attached to the window, or the window is not visible, null is returned.


It says "...or the window is not visible..." and within the onCreate() no view is yet visible :!:
:idea: Solution:
Simply put the copyWindowBitmap() to a "delayed" function, for example to the OnClickListener of a Button like this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 b.setOnClickListener(new OnClickListener(){
  2.                         @Override
  3.                         public void onClick(View arg0) {
  4.                                 ImageButton b = (ImageButton)findViewById(R.id.button4);
  5.                                 Bitmap bm = b.copyWindowBitmap(); // <null>  is no more returned!
  6.                         }
  7.                 });
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Lets us know if it helped you :)

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

copyWindowBitmap()

Postby rm123 » Thu Jan 31, 2008 4:07 pm

Thank you, this has been driving me crazy. It makes sense and i'll give it a try.
rm123
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Jan 30, 2008 5:09 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 17 guests