我正在使用演示应用程序MyView
在画布上绘制内容。FingerPaint API
我想捕捉我在画布上写的任何东西。但是当我使用View v1 = myview.getRootView()
它时,它只返回空白画布而不是内容。我想将我的绘图保存在 SDCard 中。以下是我的代码。让我知道我需要改变什么
v1 = myview.getRootView();
System.out.println("v1 value = "+v1);
v1.buildDrawingCache(true);
v1.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
//v1.layout(0, 0, v1.getMeasuredWidth(), v1.getMeasuredHeight());
v1.layout(0, 0, 100, 100);
//Bitmap b = Bitmap.createBitmap(v1.getDrawingCache());
myview.mBitmap = Bitmap.createBitmap(v1.getDrawingCache());
System.out.println("BITMAP VALue = "+myview.mBitmap);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
//b.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
File f = new File(Environment.getExternalStorageDirectory()+ File.separator + "test.jpg");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
} catch (Exception e)
{
e.printStackTrace();
}
v1.setDrawingCacheEnabled(false);
myview
MyView
是扩展的类的对象View
。