开发者

Image Filter on ROI with Java2D

开发者 https://www.devze.com 2023-02-10 13:13 出处:网络
i want apply some filters [image filter] on Region Of Interest that user selected. i need API for gett开发者_如何学Pythoning pixels of this area [polygon or freehand also Rectangle] and apply

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

i need API for gett开发者_如何学Pythoning pixels of this area [polygon or freehand also Rectangle] and apply

filter.any Suggestion for this work ?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号