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
+9.9k Golang : Text file editor (accept input from screen and save to file)
+7.3k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+16.8k Golang : Find file size(disk usage) with filepath.Walk
+14.2k Golang : GUI with Qt and OpenCV to capture image from camera
+9.3k Golang : Validate IPv6 example
+14.2k Golang : Find network of an IP address
+7k Golang : Of hash table and hash map
+19.5k Golang : Accept input from user with fmt.Scanf skipped white spaces and how to fix it
+5.2k Golang : fmt.Println prints out empty data from struct
+9k Golang : Generate random Chinese, Japanese, Korean and other runes
+10k Golang : Embed secret text string into binary(executable) file
+54.8k Golang : Unmarshal JSON from http response