无法从查看得到的位图 [英] Not able to get the bitmap from View
本文介绍了无法从查看得到的位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序,我想这是线性layout.So里面,我已经使用了图片
In my application i want the image which is inside the linear layout.So for that i have used
view.setDrawingCacheEnabled(true); // this is coming as undefined
view.buildDrawingCache(); // this is coming as undefined
Bitmap cache = view.getDrawingCache(); //here am getting null
但每当我调试code我得到空的view.getDrawingCache()。
But whenever i debug the code i am getting null at " view.getDrawingCache()".
code
public static void saveLayout(View view) {
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap cache = view.getDrawingCache();
try {
FileOutputStream fileOutputStream = new FileOutputStream(Environment.getExternalStorageDirectory() + "/ss/file.png");
cache.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
} catch (Exception e) {
// TODO: handle exception
} finally {
view.destroyDrawingCache();
}
}
用法
saveLayout(ll) // here ll is my linear layout
请让我再知道我错在哪里
Please lemme know where i went wrong
推荐答案
你能试试下面code?
Can you try below code?
view.buildDrawingCache(true);
Bitmap bitmap = view.getDrawingCache(true);
同时删除:
view.setDrawingCacheEnabled(true);
这篇关于无法从查看得到的位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文