Hello!!everyone,
is there anyway to capture screen?, I find some fuctions :
View v=tv.getRootView();
v.setDrawingCacheEnabled(true);
Bitmap bm= v.getDrawingCache();
why bm==null? help!help!


MrSnowflake wrote:V should be in the ContentView of the activity, otherwise you won't be able to capture the view. Maybe you could try to manually draw the view.


zhufan wrote:
p should be in the ContentView of the activity, otherwise you won't be able to get bitmap of the view


zhufan wrote:Hi ,survivedev
why do you get the content view? if you want to get some view of activity,you can use function "findViewById".
you can use Android' Development Tools:Hierarchy Viewer in tools folder,and then you can see the layout's hierarchy of Views in your activity


zhufan wrote:View v = this.findViewById(R.layout.hello_activity);
sure v!=null ? maybe u can use getrootview to get the top view
setContentView(R.layout.main);
bn=(Button)findViewById(R.id.bn);
iv=(ImageView)findViewById(R.id.iv);
bn.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
View v1=bn.getRootView();
v1.setDrawingCacheEnabled(true);
bm=v1.getDrawingCache();
if(bm!=null){
iv.setImageBitmap(bm);
iv.invalidate();
outputpicture();
}
}
});


Danuubz wrote:It simply works with:Using java Syntax Highlighting
Bitmap screenshot; main.setDrawingCacheEnabled(true); screenshot = Bitmap.createBitmap(main.getDrawingCache()); main.setDrawingCacheEnabled(false); Parsed in 0.036 seconds, using GeSHi 1.0.8.4
main is the content view in this case. You need Bitmap.createBitmap(main.getDrawingCache()); as the Bitmap from which the reference is received by getDrawingCache() gets recycled.


Return to Other Coding-Problems
Users browsing this forum: sumchans and 10 guests