Image Filter on ROI with Java2D
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:
- Create a BufferedImage and link it with a Graphics object
- Set clipping region
- Draw to this Graphics object
- 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.
精彩评论