feat: add GetScreenShotBuffer, GetScreenShotBase64
This commit is contained in:
parent
7da305f577
commit
ec93382e47
|
@ -1 +1 @@
|
|||
v5.0.0-beta-2503191748
|
||||
v5.0.0-beta-2503191816
|
||||
|
|
|
@ -2,6 +2,7 @@ package uixt
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/gif"
|
||||
|
@ -45,10 +46,7 @@ func (s *ScreenResult) FilterTextsByScope(x1, y1, x2, y2 float64) ai.OCRTexts {
|
|||
})
|
||||
}
|
||||
|
||||
// GetScreenResult takes a screenshot, returns the image recognition result
|
||||
func (dExt *XTDriver) GetScreenResult(opts ...option.ActionOption) (screenResult *ScreenResult, err error) {
|
||||
screenshotOptions := option.NewActionOptions(opts...)
|
||||
|
||||
func (dExt *XTDriver) GetScreenShotBuffer() (compressedBufSource *bytes.Buffer, err error) {
|
||||
// take screenshot
|
||||
bufSource, err := dExt.ScreenShot()
|
||||
if err != nil {
|
||||
|
@ -63,6 +61,29 @@ func (dExt *XTDriver) GetScreenResult(opts ...option.ActionOption) (screenResult
|
|||
"compress screenshot failed %v", err)
|
||||
}
|
||||
|
||||
return compressBufSource, nil
|
||||
}
|
||||
|
||||
func (dExt *XTDriver) GetScreenShotBase64() (base64Str string, err error) {
|
||||
compressedBufSource, err := dExt.GetScreenShotBuffer()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
base64Str = "data:image/jpeg;base64," +
|
||||
base64.StdEncoding.EncodeToString(compressedBufSource.Bytes())
|
||||
return base64Str, nil
|
||||
}
|
||||
|
||||
// GetScreenResult takes a screenshot, returns the image recognition result
|
||||
func (dExt *XTDriver) GetScreenResult(opts ...option.ActionOption) (screenResult *ScreenResult, err error) {
|
||||
// get compressed screenshot buffer
|
||||
compressBufSource, err := dExt.GetScreenShotBuffer()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
screenshotOptions := option.NewActionOptions(opts...)
|
||||
|
||||
// save compressed screenshot to file
|
||||
var fileName string
|
||||
optionsList := screenshotOptions.List()
|
||||
|
|
Loading…
Reference in New Issue