How to write a base64 decoded png image to file?

孤街浪徒 提交于 2019-12-06 16:50:15
icza

Use png.Encode() to encode an image.Image to a file (io.Writer).

The last line should be replaced with:

err = png.Encode(imgFile, pngImage)

png.Encode() will produce and send the byte sequence to the specified io.Writer (which can be an os.File of course), describing the specified image in PNG format.

Also check out this answer which contains a complete example writing an image to a file (in PNG format):

Draw a rectangle in Golang?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!