Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null bitmap for chaquopy-matplotlib project while displaying in imageview #1

Closed
sushmasrinivas57 opened this issue Aug 9, 2021 · 1 comment

Comments

@sushmasrinivas57
Copy link

sushmasrinivas57 commented Aug 9, 2021

I am creating a project similar to chaquopy-matplotlib. Bitmap is null while image is getting displayed from the byte array returned from python script

 val bytes = module.callAttr("plot",
                                            findViewById<EditText>(R.id.etX).text.toString(),
                                            findViewById<EditText>(R.id.etY).text.toString())
                    .toJava(ByteArray::class.java)
                val bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
                findViewById<ImageView>(R.id.imageView).setImageBitmap(bitmap)
import io
import matplotlib.pyplot as plt

def plot(x, y):
    xa = [float(word) for word in x.split()]
    ya = [float(word) for word in y.split()]

    fig, ax = plt.subplots()
    ax.plot(xa, ya)

    f = io.BytesIO()
    plt.savefig(f, format="png")
    return f.getvalue()

@mhsmith
Copy link
Member

mhsmith commented Aug 9, 2021

Did you close the issue because you've solved the problem? If so, what was the solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants