code: public static AffineTransform getWorldToPixel( Envelope worldEnvelope, Rectangle pixelRectangle ) {
          double width = pixelRectangle.getWidth();
          double worldWidth = worldEnvelope.getWidth();
          double height = pixelRectangle.getHeight();
          double worldHeight = worldEnvelope.getHeight();
  
          AffineTransform translate = AffineTransform.getTranslateInstance(-worldEnvelope.getMinX(), -worldEnvelope.getMinY());
          AffineTransform scale = AffineTransform.getScaleInstance(width / worldWidth, height / worldHeight);
          AffineTransform mirror_y = new AffineTransform(1, 0, 0, -1, 0, pixelRectangle.getHeight());
          AffineTransform world2pixel = new AffineTransform(mirror_y);
          world2pixel.concatenate(scale);
          world2pixel.concatenate(translate);
          return world2pixel;
      }
docs: Get the affine transform that brings from the world envelope to the rectangle.
  
  @param worldEnvelope the envelope.
  @param pixelRectangle the destination rectangle.
  @return the transform.