add byte to image function

This commit is contained in:
vcaesar 2021-05-28 14:31:05 -04:00
parent fec092bfd7
commit 0d7798c6c3

View File

@ -49,6 +49,7 @@ package robotgo
import "C"
import (
"bytes"
"fmt"
"image"
@ -1126,6 +1127,12 @@ func DecodeImg(path string) (image.Image, string, error) {
return imgo.DecodeFile(path)
}
// ByteToImg convert []byte to image.Image
func ByteToImg(b []byte) (image.Image, error) {
img, _, err := image.Decode(bytes.NewReader(b))
return img, err
}
// ToImage convert C.MMBitmapRef to standard image.Image
func ToImage(bit C.MMBitmapRef) image.Image {
bmp1 := ToBitmap(bit)