Comments (3)
Golang
的 image.Decode(...)
函数需要提前 import
指定的图片格式
如果不需要特定格式的解析, 也可以使用
_
import ( "image" _ "image/jpeg" _ "image/png" )
package main
import (
"github.com/electricbubble/gwda"
"image"
"image/jpeg" // 目标图片格式需要提前 import
"image/png" // 目标图片格式需要提前 import
"log"
"os"
)
func main() {
driver, err := gwda.NewUSBDriver(nil)
if err != nil {
log.Fatal(err)
}
screenshot, err := driver.Screenshot()
if err != nil {
log.Fatal(err)
}
_ = screenshot
img, format, err := image.Decode(screenshot)
if err != nil {
log.Fatal(err)
}
userHomeDir, _ := os.UserHomeDir()
file, err := os.Create(userHomeDir + "/Desktop/s1." + format)
if err != nil {
log.Fatal(err)
}
defer func() { _ = file.Close() }()
switch format {
case "png":
err = png.Encode(file, img)
case "jpeg":
err = jpeg.Encode(file, img, nil)
}
if err != nil {
log.Fatal(err)
}
log.Println(file.Name())
}
from gwda.
*_test.go
文件里基本上都有这些函数的常规使用
https://github.com/electricbubble/gwda/blob/master/driver_test.go#L634-L663
from gwda.
Golang
的image.Decode(...)
函数需要提前import
指定的图片格式如果不需要特定格式的解析, 也可以使用
_
import ( "image" _ "image/jpeg" _ "image/png" )package main import ( "github.com/electricbubble/gwda" "image" "image/jpeg" // 目标图片格式需要提前 import "image/png" // 目标图片格式需要提前 import "log" "os" ) func main() { driver, err := gwda.NewUSBDriver(nil) if err != nil { log.Fatal(err) } screenshot, err := driver.Screenshot() if err != nil { log.Fatal(err) } _ = screenshot img, format, err := image.Decode(screenshot) if err != nil { log.Fatal(err) } userHomeDir, _ := os.UserHomeDir() file, err := os.Create(userHomeDir + "/Desktop/s1." + format) if err != nil { log.Fatal(err) } defer func() { _ = file.Close() }() switch format { case "png": err = png.Encode(file, img) case "jpeg": err = jpeg.Encode(file, img, nil) } if err != nil { log.Fatal(err) } log.Println(file.Name()) }
感谢您的耐心解答,使我学到了 image
包的使用方式。
from gwda.
Related Issues (16)
- go get错误,建议增加相应的安装说明 HOT 3
- 如何连接指定的手机,通过usb HOT 2
- 如何区分usb上连接的两个不同设备? HOT 1
- How does USBDriver work? HOT 2
- 能不能通过IP地址连接iphone呢? HOT 1
- 多设备的话如何管理? HOT 1
- 开启抖音,跑测试的时候卡死了 HOT 1
- 使用这个gwda给视频点赞(或者点关注),会掉赞(掉关注) HOT 2
- 在执行ios自动化的时候,会出现Invalid parameter not satisfying: point.x != INFINITY && point.y != INFINITY这个错误 HOT 3
- unknown command: Unhandled endpoint: HOT 3
- 请问有支持安卓手机的版本吗? HOT 4
- demo usb连接失败是什么错误 HOT 4
- Android不可以吗 HOT 1
- src/github.com/electricbubble/gidevice/pkg/ipa/ipa.go:35:17: undefined: io.ReadAll HOT 4
- Error on info example. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gwda.