android+照相画布是反的,在Android中将画布转换为位图图像

秦弘亮
2023-12-01

以下是从画布转换为位图并将其存储到图库或特定文件夹的步骤。

注意:请确保您已获得WRITE_EXTERNAL_STORAGE的权限

activity_main.xml

android:id="@+id/linearLayout"

android:orientation="horizontal"

android:layout_margin="10dp"

android:layout_width="wrap_content"

android:layout_height="wrap_content">

android:id="@+id/drawingView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

MainActivity.java

创建父布局的参考

linearLayout.setDrawingCacheEnabled(true);

linearLayout.buildDrawingCache();

Bitmap bitmap = Bitmap.createBitmap(linearLayout.getDrawingCache());

将其存储到图库中

linearLayout.setDrawingCacheEnabled(true);

linearLayout.buildDrawingCache();

Bitmap bitmap = Bitmap.createBitmap(linearLayout.getDrawingCache());

转换为位图

linearLayout.setDrawingCacheEnabled(true);

linearLayout.buildDrawingCache();

Bitmap bitmap = Bitmap.createBitmap(linearLayout.getDrawingCache());

 类似资料: