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

Drawing Scaled Images on Canvas without interpolation

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 8, 9, 10
    • Fix Version/s: None
    • Component/s: javafx
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      A DESCRIPTION OF THE REQUEST :
      When drawing pixelated Images on a Canvas with a given width/height, they can only be drawn with Interpolation, which is not always what the developer wants. There is a workarounds by doing this yourself with PixelReader/Writer, but it performs very poorly.

      JUSTIFICATION :
      The developer sometimes Needs Control (like in Swing, or HTML5) about the interpolation method, or if it should be disabled. I.e. useful in 2D-Gamedev.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      An ability to turn off Interpolation, the resulting Image drawn with a different resolution on a canvas should be pixelated.
      ACTUAL -
      The Image is always smoothed out.

      ---------- BEGIN SOURCE ----------
      Image image = ...;
      canvas.setWidth(scale * width);
      canvas.setHeight(scale * height);
      GraphicsContext gc = canvas.getGraphicsContext2D();
      gc.drawImage(image, 0, 0, scale * width, scale * height);
      // this gives same result
      // gc.scale(scale, scale);
      // gc.drawImage(editableImage, 0, 0, width, height);
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      PixelReader reader = image.getPixelReader();
      PixelWriter writer = gc.getPixelWriter();
      for (int y = 0; y < scale * height; ++y) {
          for (int x = 0; x < scale * width; ++x) {
              writer.setArgb(x, y, reader.getArgb(x / scale, y / scale));
          }
      }

      Performs poorly and doesn't Support Transparent Pixels drawn over each other.

        Attachments

        1. download.jpg
          11 kB
          Priyanka Mangal
        2. DrawImage_Comp.png
          1.13 MB
          Priyanka Mangal
        3. DrawScaledImageTest.java
          2 kB
          Priyanka Mangal

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: