robotgo icon indicating copy to clipboard operation
robotgo copied to clipboard

Convert image []byte to C.MMBitmapRef

Open InfeCtlll3 opened this issue 5 years ago • 2 comments

  • Robotgo version (or commit ref): latest
  • Go version: go version go1.10.4 linux/amd64
  • Gcc version: gcc (Ubuntu 7.4.0-1ubuntu1~18.04) 7.4.0
  • Operating system and bit: 18.04

Hello, I'm trying to use this Lib to search blob images from a Sqlite3 db in a bigger Bitmap.

When I fetch these images from the db, they come as []byte (db store them as blobs) and I need to convert those images to C.MMBitmapRef in some way. I have tried converting them myself but had no success.

The work around I'm using is: Convert []byte to Image.image type, save it to png and then open using OpenBitmap in order to use FindBitmap.

Is there a way to convert either from []byte or Image.image type directly to C.MMBitmapRef type without having to save them to png and then openning again?

My sample code for fetching my blobs from the Database:

package main
import (
	"bytes"
	"database/sql"
	"image"
	"image/png"
	_ "github.com/mattn/go-sqlite3"
)
func main() {
	database, _ := sql.Open("sqlite3", "info.db")
	rows := database.QueryRow("SELECT image FROM marks where id=3")
        // variable id is holding the blob image file as type []bytes
	var id []byte
	rows.Scan(&id)
        // process to convert []bytes to Image.image type and then save it to png.
	img, _, _ := image.Decode(bytes.NewReader(id))
	out, err := os.Create("./output.png")
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	err = png.Encode(out, img)
}

InfeCtlll3 avatar May 19 '19 01:05 InfeCtlll3

Same question. func ToBitmapBytes(bit C.MMBitmapRef) []byte convert C.MMBitmapRef to []byte. But how to convert []byte to C.MMBitmapRef?

wilon avatar Jun 20 '19 10:06 wilon

It's not yet implemented, this is the only options currently. https://github.com/go-vgo/robotgo/blob/b49f16ed0a323a6a4bd980e8c9a7eacc6c9e87b8/base/bmp_io_c.h#L144-L246

deepio avatar Sep 26 '20 16:09 deepio