How Can I Convert A View To A Drawable?
I have a View and I want to convert it into an image in order to store it somewhere. But how can I convert this View to an image?
Solution 1:
Try this for take image of view and store in sd card..
Viewview= TextView.getRootView();
//You can use any view of your View instead of TextViewif (view != null)
{
System.out.println("view is not null.....");
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmapbm= view.getDrawingCache();
try
{
if (bm != null)
{
Stringdir= Environment.getExternalStorageDirectory().toString();
System.out.println("bm is not null.....");
OutputStreamfos=null;
Filefile=newFile(dir,"sample.JPEG");
fos = newFileOutputStream(file);
BufferedOutputStreambos=newBufferedOutputStream(fos);
bm.compress(Bitmap.CompressFormat.JPEG, 50, bos);
bos.flush();
bos.close();
}
}
catch(Exception e)
{
System.out.println("Error="+e);
e.printStackTrace();
}
}
Post a Comment for "How Can I Convert A View To A Drawable?"