绘制透明圈以外的填充 [英] Draw transparent circle filled outside

查看:97
本文介绍了绘制透明圈以外的填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我想画一个圈就专注于某一特定领域一个图形页面。但我想圆反转。即,代替的圆的内部被填充,它是透明的和其他一切被充满。看到这样的画面对我的意思(http://i.imgur.com/zxIMZ.png)。上半部分显示什么我可以做一个正常的循环。下方显示倒圈子。

I have a mapview that I want to draw a circle on to focus on a given area. But i want the circle to be inverted. That is, instead of the inside of the circle being filled, it is transparent and everything else is filled. See this picture for what i mean (http://i.imgur.com/zxIMZ.png). The top half shows what i could do with a normal circle. Bottom shows the "inverted" circle.

我试图寻找,但它一直有种很难找到我想要什么。有谁知道我怎么能去这样做这样的事情?

I've tried to search, but it's been kind of hard to find what i want. Does anyone know how i could go about doing something like this?

推荐答案

您可以创建一个新的BufferedImage,填充灰色然后删除您要圆。

You can create a new BufferedImage, fill it grey then erase the circle where you want.

然后,得出的BufferedImage您的视图的顶部。

And then, draw that BufferedImage on top of your view.

BufferedImage img = new BufferedImage(sizeX, sizeY, BufferedImage.TYPE_INT_RGBA);
Graphics2D g = img.createGraphics();

int ovalX = 50;
int ovalY = 70;
int ovalRadius = 20;

/* Draw the grey rectangle */
g.setColor(Color.GRAY);
g.fillRect(0, 0, sizeX, sizeY);

/* Enable Anti-Alias */
g.setRenderingHint(RenderingHints.HINT_ANTIALIAS, RenderingHints.VALUE_ANTIALIAS_ON);

/* Clear the circle away */
g.setComposite(AlphaComposite.CLEAR, 1.0f);
g.fillOval(ovalX - ovalRadius, ovalY - ovalRadius, 2 * ovalRadius, 2 * ovalRadius);

g.dispose();

这篇关于绘制透明圈以外的填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆