Get screen size (in pixels) for secondary monitor - matlab

Is there any way to get the screen size in pixels for a secondary monitor using Matlab? get(0,'ScreenSize') seems to only recognize the screen on the main monitor.

Try using get(0,'MonitorPositions') instead. It returns the width and height of primary and secondary monitors, in pixels.

Related

How to get physical size of the screen in flutter

How to get the screen's (or pixel's) physical width and height in flutter?
is it possible?
I need to display exactly 1 cm on different screens programaticly
Thanks.
You can use:
MediaQuery.of(context).size
/// The size of the media in logical pixels (e.g, the size of the screen).
///
/// Logical pixels are roughly the same visual size across devices. Physical
/// pixels are the size of the actual hardware pixels on the device. The
/// number of physical pixels per logical pixel is described by the
/// [devicePixelRatio].

How to get monitor resolution independent of scaling?

I need to obtain the horizontal and vertical monitor resolution, independent of the display scaling in use by Windows. At scaling of 100%, there is no problem; GetSystemMetrics(SM_CXSCREEN) returns the actual horizontal resolution of the monitor in pixels. On a 1920 x 1080 monitor, that function returns 1920. However, if the scaling is set to 125% on the same computer, GetSystemMetrics(SM_CXSCREEN) returns 1536. The problem with that is, if I use that number in a call to BitBlt() to copy the screen, it copies only a partial screen, the left three quarters or so. My program does not know that it has to use 1920 to capture the entire screen, because Windows is telling it the horizontal monitor resolution is 1536. I tried using GetDeviceCaps() and using GetMonitorInfo() to get the monitor resolution, but they return the same values as GetSystemMetrics(). Windows is reporting a monitor resolution it is not actually using for BitBlt() and also for SetPixel(). The latter function draws to a location as though the screen resolution were 1920. For example, at scaling of 125%, SetPixel() draws a pixel at the x coordinate of 1500 not near the right edge of the screen, but at about three quarters from the left. SetPixel() will draw near the right edge of the screen if I tell it to draw at the x coordinate 1900, so evidently it is not interpreting screen coordinates as reported by GetSystemMetrics().
How can I get the actual monitor resolution in pixels, regardless of the scaling?
I found a solution:
RECT rBox;
HDC hdcScreen = GetDC(NULL);
GetClipBox(hdcScreen, &rBox);
When GetClipBox() returns, rBox contains dimensions in pixels of the entire screen, regardless of scaling factor. They are the same dimensions for all scaling factors. With screen resolution set to 1920 x 1080, the function sets rBox.left to 0 and rBox.right to 1920.

Is there a way to define a view's frame in terms of inches instead of points?

Given any screen resolution, is there a way that I can figure out the amount of points in an inch? For instance, if I wanted to create an NSView that was 8.5 inches by 11 inches (like a sheet of a paper), is there an algorithm that will allow me to obtain the correct point values for the frame across many different types of Macs and screen resolutions?
It's not straightforward. I'm not sure there's a good way. I can provide an approach, but I haven't confirmed that this works reliably:
First, you can use CGDisplayScreenSize() to get the screen's physical size in millimeters. You can obtain the CGDirectDisplayID for a screen from NSScreen, which you can, in turn, get from the window. Obtain the screen's deviceDescription and get the value for the "NSScreenNumber" key. That may need to be cast to CGDirectDisplayID.
The problem from there is that the display mode may not fill the screen. It could be letterboxed or pillarboxed. Or, it might be stretched. This should be fairly uncommon these days, but still possible. You can obtain the display mode using CGDisplayCopyDisplayMode(). To determine if it's stretched, you can examine its ioFlags to see if they contain the bitmask kDisplayModeStretchedFlag (declared in IOKit).
If it's stretched, the screen's frame will have to be mapped to its size in millimeters separately for the X and Y axes. You assume the screen's frame.width (in points) maps to the full physical width, and similarly for the height.
If the mode is not stretched, you'll have to check the aspect ratio of the frame and the screen physical size to see if it's letter- or pillarboxed. If the aspect ratios are very close, then it's presumably not. That case is similar to the stretched case, but the width and height mappings should be equivalent.
If the aspect ratios differ significantly, then you compare them. If the screen's physical aspect ratio is larger than the frame's, then the screen is physically wider than the mode is using (pillarboxed). So, you compute the mapping from points to millimeters from the two heights. If the physical aspect ratio is smaller than the logical one, then the mode is letterboxed and you use the widths to compute the mapping.

Advanced image scaling in JasperReports

I need to include many images of unknown origin in a report. I have no idea what the images might be: portrait or landscape fotos, large or small, or even something with an atypical shape, like a 400x80 logo.
I'd like to scale down images with the following rule: proportionally downscale until the larger side is 200. And resulting image shouldn't take more space than needed (i.e. 1000x600 should be downscaled to 200x120, not to 200x200), so that there are no unneeded blank margins around non-square images.
Is what I need possible with JasperReports?
EDIT:
To clarify: "real size" mode is almost what I need. However, I don't see a way to limit height of resulting image. As a result, if the image I want to print is a portrait foto (or has even larger height compared to width), generated PDF looks ugly; in this case I would prefer to somehow downscale it to a smaller width.
I solved the Problem of resizing images of various sizes to a fixed size with "RetainShape" by writing an ImageResizer, based on the idea of the ImageTransformer from https://stackoverflow.com/a/39320863/8957103 , using https://github.com/rkalla/imgscalr for scaling the image.

How can you repeat a background in cocos2d when HxW lengths are not a power of 2?

While trying to create a repeated tile overlay, I've found many questions (like this one)
mentioning that repeated images in Cocos2d must have height and width dimensions that are powers of two.
This raises two questions. First, why is this a limitation? Second, and more importantly, how can I create a repeating, scrolling image that has dimensions that are not a power of two? What if I have a really wide background (say 4000 pixels) and I want it to repeat across the X axis. What should I do in that context? I can't believe the "correct" answer is to add an additional 96 pixels to the width, and increase the height of the image to 4096, as well. That's wasted bytes!
This answer has excellent info on why the need for power of 2 textures.
Why do images for textures on the iPhone need to have power-of-two dimensions?
As for your second question, the texture does not have to be square, just both the width and height have to be a power of 2. So you could have an image that is 4096x128 repeating as your background. Keep in mind also that textures, no matter what the size, are always stored in memory in an uncompressed power of two size. So an image with width of 4000 and and an image with width of 4096 are actually using the same amount of memory.