System designHow-to

Control vision display window size and screen position

Set vision display window size and screen position without changing camera capture, with aspect-ratio math, overlay mapping and desktop checks.

LumaSpec Vision9 min read Share on LinkedIn

On this page 9 sections
  1. 01Separate display geometry from inspection settings
  2. 02Create and place one persistent window
  3. 03Fit the image without changing its aspect ratio
  4. 04Apply the same transform to overlays and pointer input
  5. 05Keep display events independent of frame processing
  6. 06Diagnose ignored size and position requests
  7. 07Choose acquisition hardware separately from preview behavior
  8. 08Verify the result before handing it over
  9. 09Questions

A preview window should fit the operator’s screen without changing the images used for inspection. That requires separate controls for acquisition, analysis and presentation. Resizing the desktop window is not the same as changing the camera’s image dimensions, and shrinking a preview should not move its overlays away from the features they identify. For desktop inspection applications, the method below gives you predictable window placement, proportional image fitting and a repeatable way to diagnose ignored resize requests.

Separate display geometry from inspection settings

Keep three independent configurations: the acquired image, the analysis pipeline and the display viewport. Change only the last one when adjusting the operator interface.

Layer Settings it owns Effect of a preview resize
Acquisition Camera image dimensions, exposure and trigger mode No change
Analysis Inspection regions, calibration and algorithm input preparation No change
Presentation Window position, drawable area, zoom and display padding Image rendering changes only

If your processing library opens its own preview, check whether it exposes window geometry controls. When it does not, disable that automatic preview and send its rendered output to a window your application owns. Do not run both display paths unintentionally.

Changing camera settings to make an image fit a screen can alter inspection coverage or calibration. Keep presentation controls outside the acquisition setup described in resetting camera settings before capture.

For an ordinary operator overview, proportional fit is usually the right default. For judging individual pixels, provide a separate native-scale or zoomed inspection view.

Create and place one persistent window

Use a resizable window rather than a mode that automatically sizes itself to every incoming image. Create it once, outside the acquisition loop, and retain a stable handle or identifier.

  1. Disable any automatic preview that would create a competing window.
  2. Create your application-owned window with resizing enabled.
  3. Present an initial image, or a blank canvas with known dimensions.
  4. Allow the GUI event loop to process window creation and layout.
  5. Request the desired client-area size and desktop position through the toolkit’s documented API.
  6. Read back the actual drawable area after layout completes.
  7. Recalculate the image transform whenever that drawable area changes.

Some desktop backends need the first presentation and event dispatch before geometry requests take effect. Others accept geometry during creation. Treat that ordering as backend-specific rather than assuming every environment behaves identically.

Distinguish the outer window rectangle from its client area. A request for a 960 × 640 pixel outer window does not necessarily leave that much room for the image: borders, toolbars and status panels consume space.

Save normal window geometry when the operator finishes moving or resizing it. On the next launch, restore it only after checking that it still intersects an available display. A disconnected monitor should not leave the preview inaccessible.

Fit the image without changing its aspect ratio

Measure the image viewport after the interface has completed layout. Use the same coordinate units for its dimensions, image placement and overlay drawing. Convert between logical desktop units and framebuffer pixels explicitly when the toolkit requires it.

For an image fitted completely inside a viewport, calculate one scale factor and center the result:

s = min(viewport_width / image_width, viewport_height / image_height) rendered_width = s × image_width rendered_height = s × image_height pad_x = (viewport_width - rendered_width) / 2 pad_y = (viewport_height - rendered_height) / 2

This is a letterbox fit: the whole image remains visible, with unused space along one pair of edges. Stretching width and height independently removes that space but changes apparent proportions.

Consider an illustrative source image measuring 1920 × 1200 pixels and a viewport measuring 960 × 640 pixels:

  • Horizontal scale: 960 / 1920 = 0.5.
  • Vertical scale: 640 / 1200 ≈ 0.533.
  • Fit scale: min(0.5, 0.533) = 0.5.
  • Rendered image: 960 × 600 pixels.
  • Horizontal padding: (960 − 960) / 2 = 0 pixels.
  • Vertical padding: (640 − 600) / 2 = 20 pixels.

Keep these calculations in floating point until rasterization. If the renderer rounds the destination rectangle, use that actual rectangle for subsequent coordinate mapping.

Apply the same transform to overlays and pointer input

Store inspection results in a documented image coordinate system. Do not overwrite measurement coordinates with their screen positions.

For source-image coordinates, the forward and inverse display mappings are:

display_x = s × image_x + pad_x display_y = s × image_y + pad_y image_x = (display_x - pad_x) / s image_y = (display_y - pad_y) / s

In the worked example, an image point at (960, 600) appears at (480, 320). The arithmetic is 960 × 0.5 = 480 horizontally and 600 × 0.5 + 20 = 320 vertically.

A pointer click at (480, 320), measured relative to the viewport, therefore maps back to (960, 600). Reject clicks in the padding before converting them into inspection coordinates.

Two rendering approaches work well:

  • Draw annotations onto a display copy at source resolution, then scale that complete image.
  • Scale the image first, then transform every overlay using the same destination rectangle.

The first approach simplifies alignment. The second keeps text and line thickness readable at different window sizes. Either approach must use the results belonging to the displayed frame.

If analysis uses a resized or padded input, first reverse that preprocessing transform into source-image coordinates. Window fitting is a separate transform. The guide to camera preview overlays for motion tracking explains additional checks for overlay alignment. If orientation also changes, account for the transform order described in camera image rotation.

Keep display events independent of frame processing

A desktop window needs regular event dispatch to repaint, respond to dragging and process close requests. A long inspection operation inside the GUI callback can make a correctly configured window appear frozen.

Use the GUI thread for window operations where the toolkit requires it. Perform acquisition and analysis separately, then publish a display-ready frame with its matching results. The following is architectural pseudocode, not a particular library’s API:

acquisition_and_analysis_worker:
    acquire image
    run inspection
    publish latest display packet atomically

GUI update callback:
    read latest display packet
    measure current viewport
    calculate fit transform
    render image and matching overlays
    return promptly to the GUI event loop

window geometry callback:
    save actual geometry
    request repaint

A display packet should include the image, matching overlays, frame identifier and relevant timestamps. If the camera SDK reuses acquisition buffers, retain documented ownership or copy the preview data before publishing it.

For an operator overview, a bounded latest-frame handoff prevents old previews from accumulating. Suppose acquisition produces 60 frames per second while the display presents 20. An unbounded queue grows by 60 − 20 = 40 frames each second. After 5 seconds, 200 frames are waiting.

Discarding superseded preview packets does not mean discarding required inspections. Keep inspection records and machine decisions on their own reliable path. For freezes that persist after separating these paths, use the checks in camera preview freezes after the first frame.

Diagnose ignored size and position requests

Desktop geometry is often a request, not an absolute command. The window manager, GUI backend and session type determine what your application can control.

Symptom Likely cause Test and corrective action
Window returns to image dimensions Automatic-size mode remains active Select the documented resizable mode and check for repeated recreation
Initial size request has no effect Window layout is not complete Present once, dispatch events, then request geometry again
Image stays small inside a large window Rendering uses a fixed destination rectangle Read the current viewport and repaint using its dimensions
Desktop position is ignored Session policy restricts application placement Test user placement and persist geometry where supported
Window opens outside the visible desktop Saved coordinates belong to a removed monitor Validate saved bounds against current displays
Display appears inline rather than in a desktop window Notebook, browser or headless execution Use the environment’s supported display mechanism

Do not reapply position and size on every frame. That can fight operator actions, create flicker and trigger repeated layout work. Apply initial geometry once, then respond to deliberate layout changes.

For high-density displays, confirm whether the placement API uses logical desktop coordinates while the renderer uses physical pixels. Multi-monitor desktops can also include negative coordinates; those values are not automatically errors.

If the environment does not permit exact positioning, use a supported docked panel, application layout or operator-restored workspace. Repeated geometry calls cannot remove a window-manager restriction.

Choose acquisition hardware separately from preview behavior

Window geometry alone is not a reason to replace a camera. Select area scan cameras for the inspection’s coverage, timing and interface requirements; use the camera finder when those requirements are established.

The LS-CMR-0053 and LS-CMR-0166 are acquisition options to evaluate independently of the display implementation. Their catalog specifications describe the cameras, not the host application’s window-management behavior.

Area scan cameras12 MP GigE area scan camera, IMX226, 1/1.7" rolling shutter, 9 fps (LS-CMR-0053)LS-CMR-0053
Sensor format
1/1.7"
Interface
GigE
Resolution
12 MP
Shutter
Rolling
$560.00View partBuild a system with it
Area scan cameras12 MP USB3 area scan camera, IMX226, 1/1.7" rolling shutter, 30 fps, 4000 × 3000 resolution (LS-CMR-0166)LS-CMR-0166
Sensor format
1/1.7"
Interface
USB3
Resolution
12 MP
Shutter
Rolling
$560.00View partBuild a system with it

If the application runs on a vision controller, confirm that its installed operating environment supports the intended interactive desktop and GUI backend. A controller’s camera connectivity does not establish whether a particular session allows scripted window placement.

Keep analysis resolution tied to the inspection requirement. The guide to choosing camera resolution for dimensional inspection addresses that decision; preview dimensions address a different problem.

Verify the result before handing it over

Run these checks with both a static reference image and live acquisition:

  • Resize the viewport wider and taller. Circles should remain circular, and the whole image should remain visible in fit mode.
  • Move the window between available monitors. Check scaling, overlay placement and restored geometry.
  • Place markers near all image corners. Confirm that they stay attached while resizing.
  • Click known image locations. Verify inverse mapping and rejection of padding clicks.
  • Record image dimensions and inspection settings before and after resizing. Presentation changes should leave them unchanged.
  • Introduce a slow inspection operation. The interface should remain responsive without showing an ever-growing preview backlog.
  • Confirm that closing the preview has a documented effect. Inspection shutdown must not depend accidentally on destroying a window.

A preview close button is not a machine safety control. Keep safety functions independent of this presentation logic.

Save the chosen display mode, geometry policy and coordinate convention with the application configuration. If camera selection is also changing, start with the camera configuration step. For help separating acquisition requirements from display behavior, send the relevant image dimensions, desktop environment and symptoms through application support.

Questions

Does resizing the preview change inspection resolution?

Not when presentation is implemented separately. The inspection can continue using the original acquired image while the interface renders a scaled copy. Confirm this by logging acquisition dimensions and analysis settings during resizing, rather than assuming that a smaller visible image means a smaller processing input.

Why can window resizing work while screen positioning fails?

The desktop session may control placement, or the application may issue its request before window creation finishes. Check the GUI backend’s documented behavior, process initial layout events and inspect the resulting geometry. Where placement is restricted, use a supported workspace layout or let the operator position the window.

How do overlays stay aligned when the window changes size?

Preserve the original inspection coordinates and apply one documented image-to-viewport transform during rendering. Include any fit padding and use the actual drawable rectangle. If analysis preprocesses the image, reverse that transformation before applying display scaling, and keep results paired with the frame that produced them.

Should the preview display every acquired frame?

An operator overview can usually present the latest available result without replaying every intermediate frame. Required inspection decisions, traceability records and image archives need separate handling. A preview queue should not become the mechanism that determines whether a part was inspected or its result retained.