Image Filter on ROI with Java2D

596 views Asked by At

i want apply some filters [image filter] on Region Of Interest that user selected.

i need API for getting pixels of this area [polygon or freehand also Rectangle] and apply

filter.any Suggestion for this work ?

1

There are 1 answers

0
gwohpq9 On

Basically, what you need to do is:

  1. Create a BufferedImage and link it with a Graphics object
  2. Set clipping region
  3. Draw to this Graphics object
  4. Apply filter on the BufferedImage object

In pseudocode:

private BufferedImage bufferedImage = new BufferedImage()
private Graphics2D graphics = bufferedImage.createGraphics()

void paint(Graphics2D input) {
    graphics.clip(selectionArea.getShape())
    upperCanvas.paint(graphics)

    BufferedImageOp op
    bufferedImage = op.filter(bufferedImage, new BufferedImage())

    input.drawImage(bufferedImage)
}

For applying filter, see java.awt.image

As you can see, this can be done in java2d, but the API is quite complicated. If you're interested I can suggest pulpcore as a replacement framework. It includes several predefine filters and a one-line-API for apply them. See demo. Also includes a Java2DSprite class for easy porting between pulpcore and java2d.