장치의 화면 해상도를 특정 형식 [width]x[height](괄호없이)으로 출력합니다. 예를 들어, 출력은입니다 1440x900.
'0x0'
장치의 화면 해상도를 특정 형식 [width]x[height](괄호없이)으로 출력합니다. 예를 들어, 출력은입니다 1440x900.
'0x0'
답변:
(_=screen)=>_.width+"x"+_.height
함수로 출력합니다 return. f=시작 부분에 추가 하고처럼 호출하십시오 f(). 매개 변수 초기화를 사용하여 매개 변수 _를 screen오브젝트 로 초기화하십시오 . 나머지는 자명하다.
f=(_=screen)=>_.width+"x"+_.height
console.log(f())
참고 : 이 함수에 인수를 전달하면 실패합니다.
with(screen)alert(width+"x"+height)
내가 언젠가 사용할 것이라고 생각하지 않았습니다 with! 나는 이것이 더 골프를 칠 수 있다고 생각하지 않습니다.
s=screen,s.width+"x"+s.height(29 자)도 작동합니다.
alert: with(screen)(width+'x'+height)단지 적절한 문자열을 반환합니다.
_=screen,_.width+"x"+_.height, 29 바이트
* sigh * TI-BASIC은 모든 소문자에 대해 추가 바이트를 사용합니다.
@Timtech 덕분에 +2
@Timtech 덕분에 -3
:If ΔX>.1
:Then
:Disp "96x64
:Else
:Disp "320x240
TI-BASIC은 96 x 64 및 320 x 240의 두 가지 화면 해상도를 가진 계산기에서만 실행할 수 있기 때문에 작동합니다. 화면 해상도에 따라 다른 것으로 줌을 설정하여 어떤 화면이 있는지 확인합니다. 올바른 해상도를 출력합니다.
하드 코딩되어 있기 때문에 현재는 경쟁이 아닌 것으로 표시하고 있습니다.
ZDecimal를 사용 하지 않고 다른 Xmax비교 를 사용 하여 저장할 수 있습니다 . 또한 x1 바이트 대문자 대신 2 바이트 (x2) 인 소문자를 사용해야한다고 생각합니다 .
ZDecimal기본 줌 ( ZStandard)이 두 계산기에서 동일 하기 때문에 2 바이트 줌 (예 :)을 사용해야합니다 . 그래도 대문자를 수정하겠습니다.
ZStandard, 그래도 것 ΔX계산기를 사이에 다음 다를 수? 또한 ZDecimal1 바이트이므로 31 바이트입니다.
_=>(s=screen).width+'x'+s.height
console.log((_=>(s=screen).width+'x'+s.height)())
_=>(s=screen).width+'x'+s.height바이트 절약
/*/*/sy*r SPDisplaysDataType|awk '/so/{print$2$3$4}'
를 실행 system_profiler하고 SPDisplaysDataType정보를 얻고 첫 번째 so를 검색 Resolution하여 화면 해상도를 인쇄합니다. 여러 화면의 경우 모든 해상도를 인쇄합니다.
이전의 호환되지 않는 변형 :
/*/*/sy*r SPDisplaysDataType|grep so|tr -d 'R :a-w'
2880x1800\n1920x1080@60Hz(두 줄)을 얻었다 . 그것이 자격을 박탈하는지 모르겠습니다 ... 또는?
@60Hz이 명확하지 않습니다.
|sed 1q바이트 수를 최대 58 바이트로 가져올 수 있다고 생각합니다 .
awk여분의 바이트 로 전환하고 비준수를 수정했습니다 . :)
SysGet,w,0
SysGet,h,1
Send,%w%x%h%
확장자가 .AHK 인 파일에 저장하고 명령 프롬프트에서 실행하십시오.
Send오히려 사용 하지 MsgBox않겠습니까?
바이트를 저장해 준 @Johan du Toit에게 감사합니다!
#import<windows.h>
#define G GetSystemMetrics
f(){printf("%dx%d",G(0),G(1));}
#define G GetSystemMetrics f(){printf("%dx%d",G(0),G(1));}
Martin Ender 에게 -7 감사합니다
Leaky Nun의 -5 (실제 12!) , Regex 마법사는 저쪽에 있습니다.
이것은 길지만 끔찍한 System.Windows.Forms.SystemInformation.PrimaryMonitorSize해결책 보다 길지 않습니다.
(gwmi win32_videocontroller|% v*n)-replace" |x \d+\D+$"
먼저 Get-WmiObject( gwmi) 형식의 문자열 인 Win32_VideoController이라는 이름의 멤버가 포함 된 객체 를 검색 한 다음 정규식 바꾸기를 실행하여 올바른 형식을 얻습니다.VideoModeDescription1920 x 1080 x 4294967296 colors
PS H:\> (gwmi win32_videocontroller|% v*n)-replace" |x \d+\D+$"
1920x1080
(gwmi win32_videocontroller|% v*n)-replace" |x[^x]+$"정규식을 조정하여 몇 바이트를 면도 한다고 생각 합니다.
SystemInformation[][[1,5,2,1,2,1,2,2,;;,2]]~Infix~x
연결 한 장치에 따라 작동하지 않을 수 있습니다 (모름). 항상 작동해야합니다 (화면이 하나 이상 연결되어 있다고 가정).
Infix[Last/@("FullScreenArea"/.SystemInformation["Devices","ScreenInformation"][[1]]),x]
SystemInformation[] 폼의 표현식을 반환
SystemInformationData[{
"Kernel" -> {__},
"FrontEnd" -> {__},
"Links" -> {__},
"Parallel" -> {__},
"Devices" -> {__},
"Network" -> {__},
}]
우리는에 관심이 있으며 "Devices", 직접 SystemInformation["Devices"]또는로 액세스 할 수 있습니다 SystemInformation[][[1,5,2]]. 결과는 양식의 목록이 될 것입니다
{
"ScreenInformation" -> {__},
"GraphicsDevices" -> {__},
"ControllerDevices" -> {__}
}
우리는 원하는 "ScreenInformation"대로 SystemInformation["Devices","ScreenInformation"]또는 더 간결하게 액세스 할 수 있기를 원합니다 SystemInformation[][[1,5,2,1,2]]. 결과는 형식입니다
{
{
"ScreenArea" -> {__},
"FullScreenArea" -> {{0,w_},{0,h_}},
"BitDepth" -> _,
"Resolution" -> _
},
___
}
목록의 길이는 연결 한 화면 수입니다. 첫 번째 화면은 다음 SystemInformation[][[1,5,2,1,2,1]]과 같이 너비와 높이를 추출 할 수 있습니다. SystemInformation[][[1,5,2,1,2,1,2,2,;;,2]]그런 다음 Infix x출력 형식으로를 삽입하면 됩니다.
String f(){java.awt.Dimension s=java.awt.Toolkit.getDefaultToolkit().getScreenSize();return s.width+"x"+s.height;}
이 메소드는 awt 라이브러리를 사용하기 때문에 TIO와 같은 헤드리스 Java 설치에서는 작동하지 않습니다. 기본적으로 호출 getScreenSize은 Java Native Interface를 사용하여 화면 너비 및 화면 높이를 호출합니다 (일반적으로 C 라이브러리로).
인쇄하는 대신 문자열을 반환 할 수 있음을 상기시켜 준 Olivier Grégoire 덕분에 -9 바이트 .
...x...때문에, void f(){System.out.print((java.awt.Toolkit.getDefaultToolkit().getScreenSize()+"").replaceAll("[^\\d,]",""));}출력되는 1920,1200.. 짧은
x대신 ,몇 가지 정규식 교체를 사용하여,하지만 현재 답이 5 바이트 더 : void f(){System.out.print((java.awt.Toolkit.getDefaultToolkit().getScreenSize()+"").replaceAll("[^\\d,]","").replace(",","x"));}또는 void f(){System.out.print((java.awt.Toolkit.getDefaultToolkit().getScreenSize()+"").replaceAll(".*?(\\d+).*?(\\d+).*","$1x$2"));}자바 무거운없는 것을 잘 아 ..; P
_=>{var s=System.Windows.Forms.Screen.PrimaryScreen.Bounds;return s.Width+"x"+s.Height;};
OP가 인쇄에 대해 언급하지 않았 음 을 알려주 는 @TheLethalCoder 덕분에 -6 바이트 덕분에 문자열 반환도 괜찮습니다. 그리고 람다로 변경하여 추가 -6 바이트.
Func<string>: ()=>{var s=System.Windows.Forms.Screen.PrimaryScreen.Bounds;return s.Width+"x"+s.Height;};. 그러나 리턴 값이 void있지만 리턴 값을 리턴 string하려면 2 바이트를 추가해야합니다.
_=>{var s=System.Windows.Forms.Screen.PrimaryScreen.Bounds;return s.Width+"x"+s.Height;};
var s=System.Windows.Forms.Screen.AllScreens[0].Bounds; would also be the same count but you could golf it with that idea in mind.
read -aa<<<`xrandr`
echo ${a[7]}x${a[9]::-1}
xrandr belongs to the X server, on Ubuntu is provided by x11-xserver-utils package.
Sample run:
bash-4.3$ read -aa<<<`xrandr`;echo ${a[7]}x${a[9]::-1}
1920x1080
xrandr|grep -oP '\d+x\d+'|line
Thanks to:
Sample run:
bash-4.3$ xrandr|grep -oP '\d+x\d+'|line
1920x1080
xrandr|grep * work?
grep and sed attempts to parse xrandr's output (pastebin.com/uTVcjWCq) were longer.
xrandr|grep *|cut -d' ' -f1? (using the matching line from your paste @TIO)
from ctypes import*
u=windll.user32.GetSystemMetrics;
print u(0),'x',u(1)
print u(0),'x',u(1) is smaller and his example (link) allows it
To clarify, If it's equivalent to the output from What is my screen resolution, It's valid. in that website, there is space between each part
' '⎕R'x'⍕⌽⊃⎕WG'DevCaps'
⎕WG'DevCaps' Window Get Device Capabilities
⊃ pick the first property (height, width)
⌽ reverse
⍕ format as text
' '⎕R'x' Replace spaces with "x"s
Ox`ØP(s×Çn)±d+"x"+ight
The compressed string represents with(screen)width+"x"+height. Ox evaluates this as JavaScript, and the result is implicitly printed.
(-4 chars due to @AppleShell 's help)
Yes. it compiles.
m[3];main(){SDL_Init(32);SDL_GetDesktopDisplayMode(0,m);printf("%dx%d",m[1],m[2]);}
Run with : gcc snippet.c -lSDL2 && ./a.out
m global and omitting int: m[3];main(){...
m+1 should be shorter than m[1] right? or isn't that possible in C but only in C++? surely printf has some dereference token
Thanks @Jonathan-allan, @felipe-nardi-batista
from Tkinter import*
print'%sx%s'%Tk().maxsize()
For single display setups, this matches the output from the site. This gives entire resolution for multiple displays.
print'x'.... saves a byte
v=Tk().maxsize(), print'%sx%s'%v saves 9 bytes.
print'%sx%s'%Tk().maxsize() saves another 4 >_<
xdpyinfo|grep dim|cut -d' ' -f7
From man page:
xdpyinfo - is a utility for displaying information about an X server.
@Floris @manatwork Thanks for saving a few bytes!
-d\ instead of -d' '. Then when it comes to both grep for a line and cut a part of that line, usually is shorter with a single awk call: xdpyinfo|awk '/dim/&&$0=$2'.
dimensions but I don't have xdpyinfo on my system...
grep * expands the asterisk to all files in the directory.
grep|cut is awk.
*0. My xrandr output is *0 3360 x 1050 ( 889mm x 278mm ) *0.
-f2 Btw, Can you check xrandr|awk '/\*/{print $2}'?
just for completeness:
PRINT "256x192"
outputs 256x192. The Spectrum has a fixed hardwired screen resolution.
void setup(){fullScreen();print(width+"x"+height);}
This outputs in this format: width height. Also, the program creates a window that is the size of the screen you are using (because every Processing program creates a window by default) and this program just outputs the height and the width of this window/sketch.
WIDTHxHEIGHT.
((import html-toolkit)
(htmlOnLoad #::((var S(index(getWindow)screen))
(print(+(index S width)"x"(index S height))))))
(Line breaks added for readability)
Finally, my html-toolkit module gets some use! Only works in the Try it Online link, will not work from command line.
A few bytes could be saved if 1024 x 768 could be valid output. We just use (+ .. "x" .. ) to avoid print's implicit spacing.
2048x1080 for a true 4K screen that's actually 4096x2160. Any idea why? Firefox 52.0 on FreeBSD 11.
window.screen and getting the width and height attributes from it. I imagine if you opened up the Firefox console and typed in window.screen you'll see the apparently incorrect 2048x1080.
$ set `xrandr`;echo $6x$8
3360x1050
Tested on a CentOS 5 box with display redirected to a Cygwin machine with two monitors. Here the full xrandr output is
$ xrandr
SZ: Pixels Physical Refresh
*0 3360 x 1050 ( 889mm x 278mm ) *0
Current rotation - normal
Current reflection - none
Rotations possible - normal
Reflections possible - none
puts `xrandr`.split[7..9].join[0..-2]
Alternate solution (52 bytes):
puts `xrandr`.match(/t (\d+) (x) (\d+),/)[1..3].join