Golang : Detect number of active displays and the display's resolution
There are times when we need to find out the number of active displays and their resolution. The following code is a simple program that utilized the kbinani/screenshot
package to get the active screens' information.
The information will allow our program to properly capture screenshot or adjust our program output - such as maximizing(fullscreen) to the entire display.
Here you go!
package main
import (
"fmt"
"github.com/kbinani/screenshot"
)
func main() {
n := screenshot.NumActiveDisplays()
fmt.Println("Number of active monitor(s) : ", n)
for i := 0; i < n; i++ {
bounds := screenshot.GetDisplayBounds(i)
x := bounds.Dx()
y := bounds.Dy()
fmt.Printf("Display #%d resolution is %d x %d\n", i, x, y)
}
}
Sample output:
Number of active monitor(s) : 2
Display #0 resolution is 1920 x 1080
Display #1 resolution is 1920 x 1080
Reference :
See also : Golang : Qt get screen resolution and display on center example
By Adam Ng(黃武俊)
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+8.2k Golang : does not implement flag.Value (missing Set method)
+10.9k Golang : Get month name from date example
+11.1k Golang : Extract part of string with regular expression
+4.1k Python : Convert(cast) string to bytes example
+6k Golang : Array mapping with Interface
+10.4k Golang : Get remaining text such as id or filename after last segment in URL path
+14.9k Golang : Execute terminal command to remote machine example
+29.2k Golang : Download file example
+5.2k Golang & Javascript : How to save cropped image to file on server
+23.8k Golang : Convert uint value to string type
+11.2k Golang : Arithmetic operation with numerical slices or arrays example
+4.8k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations