- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
这里的基本问题是我绘制了一个灰度图像,并且是形状的矩形边界。我已经在该矩形上绘制了形状。现在我需要从图像中删除访问区域。
从形状获取矩形边界的代码是:
public static Rectangle getBoundingBox(Shape shape,Graphics2D g) {
int minX = Integer.MAX_VALUE;
int minY = Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE;
int maxY = Integer.MIN_VALUE;
final Rectangle polygonBounds = shape.getBounds();
int ax = polygonBounds.x;
int ay = polygonBounds.y;
int bx = ax + polygonBounds.width;
int by = ay + polygonBounds.height;
minX = Math.min(ax, minX);
minY = Math.min(ay, minY);
maxX = Math.max(bx, maxX);
maxY = Math.max(by, maxY);
final Rectangle boundingBox = new Rectangle(minX, minY, 1, 1);
boundingBox.add(maxX, maxY);
return boundingBox;
}
绘制矩形和所选形状的代码是:
Rectangle rect = getBoundingBox((Shape)selectedArea,g);
int x = (int)rect.getX();
int y = (int)rect.getY();
int width = (int)rect.getWidth();
int height = (int)rect.getHeight();
if((x+width)>grayScaledImage.getWidth()){
width = grayScaledImage.getWidth()-x;
}
if(((y+height)>grayScaledImage.getHeight())){
height = grayScaledImage.getHeight()-y;
}
BufferedImage img = grayScaledImage.getSubimage(x,y,width,height);
}
}
}
g.drawImage(img,x,y,null);
对矩形内的图像进行灰度化的代码是:
private BufferedImage toGray(BufferedImage image) {
int width = image.getWidth();
int height = image.getHeight();
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
Color c = new Color(image.getRGB(j, i));
int red = (int) (c.getRed() * 0.3);
int green = (int) (c.getGreen() * 0.59);
int blue = (int) (c.getBlue() * 0.11);
int sum = red + green + blue;
Color newColor = new Color(sum, sum, sum);
//Color newColor =Color.red;
image.setRGB(j, i, newColor.getRGB());
}
}
return image;
}
我已经尝试过 setClip() 方法,但它有某种抗锯齿问题。因此,如果能获得一些帮助那就太好了。
图像是:
需要从图像中减去浅灰度部分。
所需的图像是:
多边形可以是任何形状。
最佳答案
这里我建议你尝试一下这种方法:您可以创建一个Polygon
对象并给出xPoints
和yPoint
。像这样的事情
int[] xPoints;
int[] yPoints;
int length = xPoint.length;
Polygon polygon = new Polygon(xPoints, yPoints, length );
现在添加颜色,如下所示:
Rectangle bounds = polygon.getBounds();
for (int i = 0; i < bounds.width; i++) {
for (int j = 0; j < bounds.height; j++) {
if (polygon.contains(i, j)) {// check if the point is inside the polygon
// do the color stuff here
Color c = new Color(image.getRGB(j, i));
int red = (int) (c.getRed() * 0.3);
int green = (int) (c.getGreen() * 0.59);
int blue = (int) (c.getBlue() * 0.11);
int sum = red + green + blue;
Color newColor = new Color(sum, sum, sum);
//Color newColor =Color.red;
image.setRGB(j, i, newColor.getRGB());
}
}
}
就是这样(没有任何额外的过程)
关于java - 如何从形状中减去图像的面积,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42248908/
我有两个列表,我想从 neg 中减去列表 pos 中元素的频率。所以: neg = [x for x in all[:800000]] pos = [x for x in all[800000:]]
我有两个列表,我想从 neg 中减去列表 pos 中元素的频率。所以: neg = [x for x in all[:800000]] pos = [x for x in all[800000:]]
我正在尝试减去 2 个标准逻辑向量并得到错误 p2 <= p1(11 downto 0)- idata(11 downto 0); Error (10327): VHDL error at sub.v
我将以下代码嵌入到类中。每当我运行 distToPoint 时,它都会给出错误“不支持的操作数类型 -: 'NoneType' 和 'float'” 我不知道为什么它会返回 NoneType 和如何让
这一直让我想知道, 假设我有这种情况: select (...long sub query..) - (...long sub query..) 我想把 - 放在条件中,这意味着有时它会是 - 有时是
我有两个 vector 。我需要从 vector1 中删除 vector2 中的内容。 [编辑:不清楚这是否意味着按照下面的链接或设置差异进行逐元素减法] 我使用 Visual Studio 2010
我有一张这样的 table : id product_property_id product_id amount type 1 1 145 10
我有两个 boolean 值列表 buy_machine 和 broken_machine。我想创建第三个列表 working_machines,它是购买的机器数量的总和并减去坏机器的数量。 我尝试了
我似乎可以解决这个问题。我有两个来自 sql 的访问者/国家/地区列表 us,us,uk,fr,uk,uk,uk 和 us,uk 我用 array_count_values() 将它们制成数组: Ar
我在 javascript 中减去时间时遇到了麻烦,尽管我已经谷歌搜索了 2 天但没有任何运气:( 我正在尝试为调查问卷计时。当用户开始调查问卷时,会记录时间戳。当用户完成/单击提交时,会记录新的时间
我正在尝试对 flex 搜索中索引的字段进行一些分析。 其中两个字段是“start_time”和“end_time”。我基本上希望将这两个字段的差异分组,即('end_time'-'start_tim
我有一个函数,它接收两个 BigDecimal 数字,即 bd1 和 bd2 作为参数。该函数应减去 bd1 - db2 并返回 bd1 和 bd2 的小数位数均为 2,结果的小数位数也应仅为 2但使
根据ldt_code中的ld源代码here。没有将dl_main传递给phdr的上下文,我对为什么通过减去虚拟地址来推断main_map的加载地址有些困惑。 我跟踪过的代码: 1124 static
我进行了多次重复测量的治疗,我想减去每次治疗的每个时间点的对照值。数据集的形状是这样的,有多年、物种和处理。 ID Year Species Treatment value 1 2010 x
我正在尝试查找一次旅行的矩形区域,可以在此处找到更多上下文 我在下面的代码中遇到的错误是: "Exception in thread "main" java.lang.ArrayIndexOutOfB
我一直在尝试使用 pandas dataframe 减去我读入 python 的列之间的日期和时间。我写的代码如下: Time = df['t'] - df['t'].shift(1) + df['t
I want to subtract all values in a[nn,...,0] by b[nn] while keeping the original structure of the ar
假设我有两个列表:List l1,和 Listl2 请帮助我如何在 2 个列表之间合并、减去和相交。谢谢。 注意:我使用的是 .NET 2.0,所以我不能使用 LINQ。谢谢。 最佳答案 以下是伪代码
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我正在尝试运行以下代码: extern crate unicase; use unicase::UniCase; use std::collections::HashSet; fn main() {
我是一名优秀的程序员,十分优秀!