m0s
m0s

Reputation: 4280

How to get the Shape of the transparent portion of a BufferedImage in Java?

I have BufferedImage image objects which have transparent pixels. What I'd like to get is Shape or Area objects which enclose the transparent portion of the image.

Upvotes: 2

Views: 188

Answers (1)

Rom1
Rom1

Reputation: 3207

You could try it that way: treat the original image as an undirected graph whose nodes are the transparent pixels. Put an edge between adjacent nodes on the image (i.e. transparent pixels that are directly above, left, right, below, and diagonal). Find the connected components for that graph. Then for each connected component, compute its convex hull. Return a List containing each of those hulls, each hull being a Shape.

Upvotes: 1

Related Questions