我正在尝试拍摄滚动视图的所有内容(也在页面外)。我遇到的问题是,当它到达行Bitmap b = u.getDrawingCache();
时,抛出异常“nullPointerException”。我似乎无法弄清楚造成这种情况的原因。这是我的代码:
if(v.getId() == R.id.btnSnap)
{
try
{
View u = findViewById(R.id.svContent);
u.setDrawingCacheEnabled(true);
ScrollView z = (ScrollView) findViewById(R.id.svContent);
int totalHeight = z.getChildAt(0).getHeight();
int totalWidth = z.getChildAt(0).getWidth();
u.layout(0, 0, totalWidth, totalHeight);
u.buildDrawingCache(true);
Bitmap b = u.getDrawingCache();
//Just so that I can get a quick preview of
//what the picture looks like
ImageView img = (ImageView)findViewById(R.id.ivTest);
img.setImageBitmap(b);
//Save the picture
File fileName = new File(context.getExternalFilesDir(null)+"/ArcFlash/SafetyCheckList1.png");
FileOutputStream out = new FileOutputStream(fileName);
b.compress(Bitmap.CompressFormat.PNG, 90, out);
out.close();
}
catch(Exception ex)
{
handler.Log(ex.getMessage(), "onClick(SafetyCheckList.java)", context);
}
}
编辑问题似乎在u.layout(0, 0, totalWidth, totalHeight);