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
+3.8k Linux/MacOSX : How to symlink a file?
+29k Golang : Calculate percentage change of two values
+6.8k Swift : Convert (cast) String to Double
+19.5k Golang : Clean up null characters from input data
+8.9k Golang : Get current, epoch time and display by year, month and day
+11.3k Golang : Sort and reverse sort a slice of bytes
+8.3k Golang : Changing a RGBA image number of channels with OpenCV
+13.3k Golang : How to filter a map's elements for faster lookup
+7.5k Golang : Another camera capture GUI application with GTK and OpenCV
+4.3k JavaScript/JQuery : Redirect page examples
+4.9k Golang : Launching your executable inside a console under Linux
+14.6k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy