1

我一直在尝试通过 Chaquopy 使用 matplotlib 在 Android 中绘制数据。到目前为止,在 Chaquopy 中自己创建地块非常容易。但是,我不清楚如何保存绘图并将其加载到 ImageView 中。我查看了这个示例(How to display python matplotlib graphs (png) with Chaquopy in Android Studio),这似乎是一个很有前途的方法,但它涉及在 Python 中绘图,将图像存储为字节对象,然后加载字节对象到 Java 中的 ImageView 中。理想情况下,我希望能够从 python 脚本中完成所有这些工作,包括更新 ImageView。这可能吗?

感谢您的任何帮助和建议!

编辑:我找到了一个完全避免字节对象的解决方案:

root = Environment.getExternalStorageDirectory()
plt.savefig(root.getAbsolutePath() + "/fig1.png")
bitmap = BitmapFactory.decodeFile(root.getAbsolutePath() + "/fig1.png")
self.findViewById(R.id.imageView).setImageBitmap(bitmap)

如果有人有使用字节对象的解决方案,尽管我欢迎任何建议。

4

0 回答 0