In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today, the editor will share with you the relevant knowledge points about how to achieve screen screenshots in go language. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
Install go get github.com/kbinani/screenshot custom screenshot Capturefunc Capture (x, y, width, height int) (* image.RGBA, error) with the help of third-party libraries
Returns a screenshot of the specified desktop area. XQuery y is the starting point coordinate, and width,height is the width and height of the picture.
Full screen screenshot CaptureDisplayfunc CaptureDisplay (displayIndex int) (* image.RGBA, error)
Return to full screen screenshot. DisplayIndex is the display number, and the default screen is 0. If there are multiple external displays, it is 1, 2, 3, 4. .
Get the number of active monitors NumActiveDisplaysfunc NumActiveDisplays () int
Returns the number of active monitors.
Gets the specified screen display range GetDisplayBoundsfunc GetDisplayBounds (displayIndex int) image.Rectangle
GetDisplayBounds returns the display range of the displayIndex, starting at (0mem0) coordinates and ending with the current screen resolution, for example: (0meme0)-(1920meme1080).
Get a screenshot of the custom rectangular region CaptureRectfunc CaptureRect (rect image.Rectangle) (* image.RGBA, error)
Capture the specified area of the desktop. Similar to Capture, it is mainly used with GetDisplayBounds.
The parameter is a rectangle, that is, two points, a minimum point and a maximum point
Demo package mainimport ("fmt"github.com/kbinani/screenshot"image"image/png"os") / / save * image.RGBA to filePath with PNG format.func save (img * image.RGBA, filePath string) {file, err: = os.Create (filePath) if err! = nil {panic (err)} defer file.Close () png.Encode (file) Img)} func main () {/ / Custom screenshot img, err: = screenshot.Capture (0,0500,500) if err! = nil {panic (err)} save (img, "custom .png") / / get all active screens n: = screenshot.NumActiveDisplays () if n 0 {for I: = 0 I < n Err + {img, err = screenshot.CaptureDisplay (I) if err! = nil {panic (err)} fileName: = fmt.Sprintf ("% d screenshot .png", I) save (img FileName)}} / / use Rectangle custom screenshot / / get the first screen display range var new image.Rectangle = image.Rect (0,0600,700) img, err = screenshot.CaptureRect (new) if err! = nil {panic (err)} save (img, "new.png") / / use GetDisplayBounds to obtain the specified screen display range Full screen screenshot bounds: = screenshot.GetDisplayBounds (0) img, err = screenshot.CaptureRect (bounds) if err! = nil {panic (err)} save (img, "all.png") / / use Union to get the minimum and maximum points of the specified screen rectangle var all image.Rectangle = image.Rect (0,0,0) 0) bounds1: = screenshot.GetDisplayBounds (0) all = bounds1.Union (all) fmt.Println (all.Min.X, all.Min.Y, all.Dx (), all.Dy ())} these are all the contents of the article "how to implement screenshots in go language" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.