douba8048 2018-02-21 12:25
浏览 66

转到gonum图,将png数据存储到数据库

I am generating some Histograms from the gonum/plot library in Go. Normally you would save the image, as .png for instance like this:

if err := plot.Save(2.5*vg.Inch, 2.5*vg.Inch, "my_histo.png"); err != nil {
    log.Println("[!] error creating plot", err)
}

And this generates all the .png at the folder. No issue with that.

I want to use this plots on a GUI(Python tk) and basically I want to store them in an SQLITE database, with a text key that corresponds to the physical object, which this histogram data was generated from, in order to access them from Python. On the GUI, there is a dictionary and you choose which histogram data you wish to display, and this is synced from the database.

I want to save this png Histogram at a column in my Database that it is Blob type and then I want to extract it from there, when needed.

Now, I know that this might not be the best way to implement this, but I would like to understand how Reader/Writer works, so I would like to know if I can do what I describe and if yes, how?

For example, I can generate those png histograms on a folder and then save the location that they were saved as a text at the database, instead of sending larger amount of bytes, but I was wondering if I can avoid saving the png and save it directly at the database, as a []bytes possible?

To that extend, I noticed that my plot object has the attribute WriterTo and I can do something like this:

n, err := plot.WriterTo(2.5*vg.Inch, 2.5*vg.Inch, "png")

This returns the number of bytes written, and if there was an error. So, what is this actually useful for? How do I access my data/png, after using this WriterTo method?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
    • ¥15 js,页面2返回页面1时定位进入的设备
    • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号