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
+12.8k Golang : Increment string example
+8k Golang : How to check variable or object type during runtime?
+8.6k Android Studio : Indicate progression with ProgressBar example
+5.1k PHP : Convert CSV to JSON with YQL example
+8.4k Golang : Take screen shot of browser with JQuery example
+4.7k Golang : Display packages names during compilation
+15k Golang : Force download file example
+6.4k Golang : How to setup a disk space used monitoring service with Telegram bot
+12.1k Android Studio : Highlight ImageButton when pressed on example
+11.3k Get form post value in Go
+3.9k Golang : Converting individual Jawi alphabet to Rumi(Romanized) alphabet example