0

我使用 APIDemo 的 FingerPaint 应用程序完成了一个示例绘画应用程序。代替 setContentView(R.layout.main) 的“通常”模式,它使用类 MyView 扩展 View 并将内容设置为 setContentView(new MyView(this)); 现在无论我画什么,我都想将它保存在 SDCard 中。为此,我需要使用 getRootView 了解 rootview。这是由布局对象获得的(例如:LinearLayout L1 = new...)L1.getRootView。因为我使用的是这个 MyView,所以我无法获取 rootview 也无法保存位图。

    myview.setDrawingCacheEnabled(true);
    myview.requestFocus();
    myview.getRootView();

    System.out.println("MYVIEW = "+myview);

    myview.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
    MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    myview.layout(0, 0, myview.getMeasuredWidth(), myview.getMeasuredHeight());

    myview.buildDrawingCache(true);
    mBitmap = myview.getDrawingCache();
    //System.out.println("myview.getDrawingCache() = "+newview.getDrawingCache());

    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    myview.setDrawingCacheEnabled(false); // clear drawing cache
    System.out.println("BITMAP = "+mBitmap);

    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();
    }

我想知道如何使用菜单按钮单击保存我的绘图?

谢谢

4

1 回答 1

0

After a lot of effort into research I bumped into this http://blahti.wordpress.com/2010/11/18/how-to-save-jpeg-files-in-the-android-emulator/ This solved my issue of saving the drawing.

于 2012-04-12T14:26:28.287 回答