如何在Java中获取BufferedImage透明部分的Shape?
我有具有透明像素的 BufferedImage 图像对象。我想要得到的是包含图像透明部分的 Shape
或 Area
对象。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以这样尝试:将原始图像视为无向图,其节点是透明像素。在图像上的相邻节点之间放置一条边(即正上方、左、右、下和对角线的透明像素)。找到该图的连接组件。然后对于每个连接的组件,计算其凸包。返回一个包含每个外壳的
List
,每个外壳都是一个Shape
。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 aShape
.