Monday, May 9, 2011

Capture Screen in Android

Capturing screen is a very useful thing in lot of projects. We can use it for thumbnail, in some cases can use it for Animations etc. This post mainly shows the power of setDrawingCacheEnabled() method in Android's View class. Most common use is take the screen shot and use it as a thumbnail. Take a view from the layout xml file and use the code snippet,


TextView tv = (TextView) findViewById(R.id.text);
View img = (View) findViewById(R.id.view);
img = tv.getRootView();
img.setDrawingCacheEnabled(true);
Bitmap bmp = img.getDrawingCache();
ImageView image = (ImageView) findViewById(R.id.img);
image.setImageBitmap(bmp);

No comments:

Post a Comment

Androidians