Пример #1
0
  protected Response returnEmptyTile(final int width, final int height, final String format)
      throws Exception {
    // return an empty image
    ImageResponseWriter writer =
        (ImageResponseWriter) ImageHandlerFactory.getHandler(format, ImageResponseWriter.class);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    int bands;
    Double[] nodatas;
    if (format.equalsIgnoreCase("jpg") || format.equalsIgnoreCase("jpeg")) {
      bands = 3;
      nodatas = new Double[] {0.0, 0.0, 0.0};
    } else {
      bands = 4;
      nodatas = new Double[] {0.0, 0.0, 0.0, 0.0};
    }

    Raster raster =
        RasterUtils.createEmptyRaster(width, height, bands, DataBuffer.TYPE_BYTE, nodatas);
    writer.writeToStream(raster, ArrayUtils.toPrimitive(nodatas), baos);
    byte[] imageData = baos.toByteArray();
    IOUtils.closeQuietly(baos);

    final String type = mimeTypeMap.getContentType("output." + format);
    return Response.ok(imageData).header("Content-Type", type).build();

    // A 404 - Not Found response may be the most appropriate, but results in pink tiles,
    // maybe change that behavior on the OpenLayers client?
    // return Response.status( Response.Status.NOT_FOUND).build();

  }
Пример #2
0
  protected static Response createEmptyTile(
      final ImageResponseWriter writer, final int width, final int height) {
    // return an empty image
    final int dataType;
    if (writer.getResponseMimeType().equals("image/jpeg")) {
      dataType = BufferedImage.TYPE_3BYTE_BGR;
    } else {
      // dataType = BufferedImage.TYPE_INT_ARGB;
      dataType = BufferedImage.TYPE_4BYTE_ABGR;
    }

    final BufferedImage bufImg = new BufferedImage(width, height, dataType);
    final Graphics2D g = bufImg.createGraphics();
    g.setColor(new Color(0, 0, 0, 0));
    g.fillRect(0, 0, width, height);
    g.dispose();

    return writer.write(bufImg.getData()).build();
  }