mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-01 14:43:55 +00:00
add ToBitmapBytes examples code
This commit is contained in:
parent
8d588443b3
commit
8969268af6
36
examples/bitmap-bytes/main.go
Normal file
36
examples/bitmap-bytes/main.go
Normal file
@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log"
|
||||
|
||||
"image/jpeg"
|
||||
_ "image/jpeg"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/go-vgo/robotgo"
|
||||
"golang.org/x/image/bmp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
bitMap := robotgo.CaptureScreen()
|
||||
defer robotgo.FreeBitmap(bitMap)
|
||||
|
||||
bs := robotgo.ToBitmapBytes(bitMap)
|
||||
img, err := bmp.Decode(bytes.NewReader(bs))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
b := new(bytes.Buffer)
|
||||
err = jpeg.Encode(b, img, &jpeg.Options{20})
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Println("bytes: ", b.Bytes())
|
||||
|
||||
ioutil.WriteFile("out.jpg", b.Bytes(), 0666)
|
||||
}
|
Loading…
Reference in New Issue
Block a user