Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8233838

Low resolution of snapshot for high resolution screen

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: openjfx13
    • Fix Version/s: tbd
    • Component/s: javafx
    • Labels:
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      A DESCRIPTION OF THE PROBLEM :
      With Java 8, snapshot() returns image WYSIWYG.
      With later JavaFx, snapshot() returns image in very lower solution for high resolution screen.

      REGRESSION : Last worked in version 13.0.1

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Physical screen is high resolution like 4k.
      2) Put some texts in a Label, and make it looks clear in screen.
      3) Run snapshot() of this label and wirte it as an image file
      4) Open the image file by different image viewer tools

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The snapshot is same clear and same size as the control is viewed on screen .
      ACTUAL -
      The snapshot looks blur

      ---------- BEGIN SOURCE ----------
      Label label = new Label("Test resolution");
      Image snap = label.snapshot(new SnapshotParameters(), null);
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      http://news.kynosarges.org/2017/02/01/javafx-snapshot-scaling/

      As above article, I get clearer snapshots:
      ------------------------------------------------------------------
                  Bounds bounds = webView.getLayoutBounds();
                  double scale = Toolkit.getDefaultToolkit().getScreenResolution() / Screen.getPrimary().getDpi();
                  if (scale < 1) scale = 1;
                  int imageWidth = (int) Math.round(bounds.getWidth() * scale);
                  int imageHeight = (int) Math.round(bounds.getHeight() * scale);
                  SnapshotParameters snapPara = new SnapshotParameters();
                  snapPara.setFill(Color.TRANSPARENT);
                  snapPara.setTransform(javafx.scene.transform.Transform.scale(scale, scale));
                  WritableImage snapshot = new WritableImage(imageWidth, imageHeight);
                  snapshot = webView.snapshot(snapPara, snapshot);
      ------------------------------------------------------------------

      In my env:
      "Toolkit.getDefaultToolkit().getScreenResolution()" returns 216
      "Screen.getPrimary().getDpi()" returns 72
      "Screen.getPrimary().getOutputScaleX()" returns 2.25

      I did not use "Screen.getPrimary().getOutputScaleX()" because:
                 2.25 * 96 = 216
                 2.25 * 72 = 162
      So I guess ratio 216 / 72 = 3 may be better.

      The bad thing of this workaournd is that the generate images are really larger since they are actually scaled.
      What I expect is WYSIWYG: same size and same resolution as they are viewed on screen.

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              arapte Ambarish Rapte
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: