code: public byte[] getRL2Image( Geometry geom, String geomEpsg, int width, int height ) throws Exception {
          String sql;
          String rasterName = getName();
          if (geomEpsg != null) {
              sql = "select GetMapImageFromRaster('" + rasterName + "', ST_Transform(ST_GeomFromText('" + geom.toText() + "', "
                      + geomEpsg + "), " + srid + ") , " + width + " , " + height
                      + ", 'default', 'image/png', '#ffffff', 0, 80, 1 )";
          } else {
              sql = "select GetMapImageFromRaster('" + rasterName + "', ST_GeomFromText('" + geom.toText() + "') , " + width + " , "
                      + height + ", 'default', 'image/png', '#ffffff', 0, 80, 1 )";
          }
  
          return database.execOnConnection(mConn -> {
              try (IHMStatement stmt = mConn.createStatement()) {
                  IHMResultSet resultSet = stmt.executeQuery(sql);
                  if (resultSet.next()) {
                      byte[] bytes = resultSet.getBytes(1);
                      return bytes;
                  }
              }
              return null;
          });
      }
docs: Extract an image from the database.
  
  @param geom the image bounding box geometry.
  @param width the pixel width of the expected image.
  @param height the pixel height of the expected image.
  @return the image bytes.
  @throws Exception