What's the best way to fill or paint around an image in Java?

Posted by wsorenson on Stack Overflow See other posts from Stack Overflow or by wsorenson
Published on 2010-03-15T20:53:24Z Indexed on 2010/03/15 21:19 UTC
Read the original article Hit count: 526

Filed under:
|
|
|
|

I have a set of images that I'm combining into a single image mosaic using JAI's MosaicDescriptor.

Most of the images are the same size, but some are smaller. I'd like to fill in the missing space with white - by default, the MosaicDescriptor is using black. I tried setting the the double[] background parameter to { 255 }, and that fills in the missing space with white, but it also introduces some discoloration in some of the other full-sized images.

I'm open to any method - there are probably many ways to do this, but the documentation is difficult to navigate. I am considering converting any smaller images to a BufferedImage and calling setRGB() on the empty areas (though I am unsure what to use for the scansize on the batch setRGB() method).

My question is essentially:

  • What is the best way to take an image (in JAI, or BufferedImage) and fill / add padding to a certain size?
  • Is there a way to accomplish this in the MosaicDescriptor call without side-effects?

For reference, here is the code that creates the mosaic:

    for (int i = 0; i < images.length; i++) {
        images[i] = JPEGDescriptor.create(new ByteArraySeekableStream(images[i]), null);

        if (i != 0) {
            images[i] = TranslateDescriptor.create(image, (float) (width * i), null, null, null);
        }
    }

    RenderedOp finalImage = MosaicDescriptor.create(ops, MosaicDescriptor.MOSAIC_TYPE_OVERLAY, null, null, null, null, null);

© Stack Overflow or respective owner

Related posts about java

Related posts about image