inflate了一个View,填充完内容之后,并不打算把它显示在屏幕上只想获得它的截图然后作为imageview显示在另外的地方我用了下面的代码LayoutInflater mInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
FrameLayout mIconLayout = (FrameLayout)mInflater.inflate(R.layout.forlder_icon_creator, null, false);
//之后对layout的一些内容进行了填充
mIconLayout.setDrawingCacheEnabled(true);
mIconLayout.buildDrawingCache();
Bitmap bitmap = mIconLayout.getDrawingCache();
但是获得的bitmap是null,求问正确的操作步骤。。
FrameLayout mIconLayout = (FrameLayout)mInflater.inflate(R.layout.forlder_icon_creator, null, false);
//之后对layout的一些内容进行了填充
mIconLayout.setDrawingCacheEnabled(true);
mIconLayout.buildDrawingCache();
Bitmap bitmap = mIconLayout.getDrawingCache();
但是获得的bitmap是null,求问正确的操作步骤。。
解决方案 »
- 编译一个模块时出现undefined reference to `__android_log_print'
- 求教如何判断android页面加载完毕
- android
- 求助!无法使用eclipse导出apk!
- 短信在android 2.2能被拦截在android 4.0上不能被拦截~求大神帮忙~谢谢
- listview拖动优化问题
- 求助:(android)如何保证程序不被系统杀死
- 急!在Activity中开启一个线程连接我的服务器,如果连不上就继续连接
- android 状态栏电池图标定制问题
- 求大佬帮忙看一下这是怎么了
- Android初学者的学习笔记(陆续更新)
- 关于android的button控件
public void saveScreen(View parent) {
boolean flag = false;
if (Environment.MEDIA_MOUNTED.equals(Environment
.getExternalStorageState())) {// sdcard已装载
FileOutputStream fos = null;
Bitmap temp = null;
try {
parent.setDrawingCacheEnabled(true);
parent.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
temp = parent.getDrawingCache(true);
String prefix = Util.instance().format(new java.util.Date());
if (Settings.getSSDir() != null) {
String filepath = Settings.getSSDir() + "/" + prefix
+ ".jpg";
File file = new File(filepath);
if (!file.exists()) {
file.createNewFile();
}
fos = new FileOutputStream(file);
if (temp != null) {
flag = temp.compress(CompressFormat.JPEG, 90, fos);
fos.flush();
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fos != null) {
fos.close();
fos = null;
}
if (temp != null && flag) {
parent.setDrawingCacheEnabled(false);// 这里必须设置为false,否则回收temp后会产生
// 使用回收图片错误
temp.recycle();
temp = null;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}传入你inflate得到的View,试试看能不能行