필터 지우기
필터 지우기

Change the Unit of the 'LineWidth'-property to pixels (not points)

조회 수: 19 (최근 30일)
Tom
Tom 2023년 2월 10일
댓글: Tom 2023년 2월 10일
Dear Mathworks community,
I am currently working on a precise UI to plot some symbols that I create by plotting several lines in the same plot. The Problem that I have is, that I have the size of the lines in Pixels, but not in inches (points).
I know that there is a property called 'FontUnits' for the text size, where you can set the unit of the 'FontSize'-property to pixels, but now I also need a way to set the LineWidth in pixels as well.
I thank you for your help!

채택된 답변

Smit
Smit 2023년 2월 10일
Hi,
I understand you want to know if there is a way to change the units of the “LineWidth” property to pixels instead of inches.
There isn’t a way to use pixels as units in the “LineWidth” property. You could possibly use the following workaround.
The “LineWidth” property uses the points as units, where 1 point = 1/72 inches as given in the documentation. You can also find out the “ScreenPixelsPerInch” property of your screen using the “get” operation as follows
get(0,'ScreenPixelsPerInch')
Using this information, you can calculate how many points equal a pixel.
inchesPerPixel = 1/get(0, 'ScreenPixelsPerInch');
pointsPerPixel = 72*inchesPerPixel;
And then use the calculated number of points to set “LineWidth”.
Hope this helps!
  댓글 수: 1
Tom
Tom 2023년 2월 10일
Thanks a lot! That´s exactly what I was looking for.
I appreciate your detailed explanation, have a great day!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2023년 2월 10일
That is not possible. Lines are literally in pixels. Zooming an area containing a line does not make the line thicker. Zooming out from. an area with a lot of lines can result in nothing other than line pixels with nothing between them.
  댓글 수: 3
Tom
Tom 2023년 2월 10일
@Walter Roberson I am not quite sure what you´re saying with "lines are literally in pixels".
Walter Roberson
Walter Roberson 2023년 2월 10일
Lines are generated by the graphics hardware as being literally one pixel wide, independent of the current resolution settings. They are the thinnest possible graphics object.
High DPI correction does weird things to units. Points no longer refers to 1/72 of a inch and now has to do with virtual resolutions if I recall correctly.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by