Golang Converting image.Image to []byte

前端 未结 2 1682
难免孤独
难免孤独 2021-01-31 04:31

Having trouble converting an image.Image to []byte. The problem spot is wrapped in dotted lines.

image_data, err := mybucket.Get(key)

if err != nil {
    panic         


        
2条回答
  •  没有蜡笔的小新
    2021-01-31 04:40

    You want a bytes.Buffer, not a bufio.Writer. bytes.Buffer is used when you need a writer that writes to memory. bufio.Writer just caches data in memory before forwarding it to another writer.

    buf := new(bytes.Buffer)
    err := jpeg.Encode(buf, new_image, nil)
    send_s3 := buf.Bytes()
    

提交回复
热议问题