首页 > 解决方案 > 将布局保存到图库

问题描述

我正在写一个笔记应用程序,想将整个布局保存到一个图像中,并将其保存在我的画廊中或与其他应用程序共享。我不知道从哪里开始,所以使用了库Layout_to_image。但我有一个错误在线:bitmap=layout_to_image.convert_layout(); 这是错误:原因:java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法“int android.graphics.Bitmap.getWidth()”

这是我的代码

    AppCompatTextView txt_screen;
    Bundle bundle;

    Layout_to_Image layout_to_image;
    Bitmap bitmap;
    RelativeLayout theWholeLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_screen_note);
        bundle = getIntent().getExtras();
        String description = bundle.getString("description");
        txt_screen = findViewById(R.id.txt_screen);
        theWholeLayout = findViewById(R.id.theWholeLayout);
        txt_screen.setText(description);
        layout_to_image = new Layout_to_Image(ScreenNoteActivity.this, theWholeLayout);
            bitmap = layout_to_image.convert_layout();

任何帮助表示赞赏。

标签: imagebitmap

解决方案


推荐阅读