- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想使用 Graphics.fillRoundRect() 填充一个区域,但我希望它中间的一个矩形不被填充。
本质上,给定一个 100x30 的组件,我想将裁剪设置为 10,10 处大小为 80x10 的矩形,但填充仅绘制该 80x10 矩形外部的区域。原因是我想要一个 n 像素的边框,在不影响内部组件区域的情况下绘制一个弯曲的轮廓。
到目前为止,我能看到的最好的方法是裁剪到 10,10 90x10 并执行 fillRoundRect(),然后裁剪到 90,10 10x10 并执行 fillRect() 以填充右侧、下方和上方角落。
如果我简单地重新绘制一个单线矩形,那么我最终会在角上“发现”,因为曲线并没有完全邻接(和/或因为 AA 影响周围的像素)。
编辑:警告 - 我需要一种方法来完成它,它可以与 J2ME AWT(CDC with Personal Profile 1.1)以及 J2SE 一起工作。
编辑:另一个similar question有一个 an answer我能够适应。适合我的情况的代码作为 self 回答发布。
最佳答案
我有一个 similar answer关于另一个问题,即使用多边形作为 AWT 剪辑。也许这在 J2ME 中受支持?您需要知道要排除的矩形的边界,以及绘图区域的外边界。
+-------------------+| clip drawing area |+---+-----------+ || | excluded | || | area | || +-----------+ || |+-------------------+
EDIT FROM OP.
This answer worked for me and the API's are supported on J2ME. The answer of the other question appears to have one mistake - the set of coordinates needs to start a the point on the outer-left and inner top in order to create an enclosed polygon. My final code which worked follows:
To create a clipping Shape, I used this method:
static public Shape getOutsideEdge(Graphics gc, Rectangle bb, int top, int lft, int btm, int rgt) {
int ot=bb.y , it=(ot+top);
int ol=bb.x , il=(ol+lft);
int ob=(bb.y+bb.height), ib=(ob-btm);
int or=(bb.x+bb.width ), ir=(or-rgt);
return new Polygon(
new int[]{ ol, ol, or, or, ol, ol, il, ir, ir, il, il },
new int[]{ it, ot, ot, ob, ob, it, it, it, ib, ib, it },
11
);
}
我将其设置到图形上下文中,然后填充我的矩形:
Rectangle tmp=new Rectangle(px,py,pw,ph);
gc.setClip(getOutsideEdge(gc,tmp,thickness,thickness,thickness,thickness));
gc.fillRoundRect(px,py,pw,ph,RADIUS,RADIUS);
然后我通过在每个角上画一个点来创建圆角内角的错觉:
gc.setClip(px,py,pw,ph);
gc.drawLine((px +thickness ),(py +thickness ),(px +thickness ),(py +thickness ));
gc.drawLine((px+pw-thickness-1),(py +thickness ),(px+pw-thickness-1),(py +thickness ));
gc.drawLine((px +thickness ),(py+ph-thickness-1),(px +thickness ),(py+ph-thickness-1));
gc.drawLine((px+pw-thickness-1),(py+ph-thickness-1),(px+pw-thickness-1),(py+ph-thickness-1));
关于java - 有什么方法可以让 "inverted"剪辑区域用于 Java 绘画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1273688/
我正在阅读有关 Elasticsearch 的信息。看起来它维护所有文档中所有术语的倒排索引。但它是否也保持正常的索引,即从文档 id 到文档?此外,由于它在所有字段和所有术语上维护大量索引,所以它占
我正在做一个时间序列问题。当我在做 AR 模型时,一切正常。 # Import the module for estimating an ARMA model from statsmodels.tsa
是否可以使用Scala解析器组合器反转匹配?我正在尝试使用不以一组关键字开头的解析器来匹配行。我可以使用一个烦人的零宽度负前瞻正则表达式(例如"(?!h1|h2).*")来做到这一点,但我宁愿使用Sc
假设我有一个可以接受 optional 参数的函数,如果参数是 Some,我想返回 None,如果参数是 0x251812231343,则返回 None: def foo(a: Option[A]):
根据我对集合论的了解,当您取两个集合的并集时,您会覆盖两个集合并取结果集。当你取两个集合的交集时,你将两个集合重叠并取彼此重叠的部分。 对于数字,这很好用: type SomeUnion = (1 |
我有一个日期时间列表,我需要“反转”(因为缺少更好的词)这个列表。 public class Available { public Available(DateTime startDate,
我正在尝试反转键/值。 所以,我正在尝试这样的事情: var _ = require('underscore'); var myObj = [ {'name': 'Mike', 'number
是否有任何 .NET 类型可以表示一组键值对,其中每个键仅与单个值配对(如常规 Dictionary ),但每个值也仅与单个键配对?我一直认为这是一个“可逆”字典,因为您可以将键与值交换而不会发生任何
我正在寻找一种使用 NUnit 编写单元测试的方法,这样如果当前测试需要超过 X 毫秒才能完成,它应该终止并将其报告为已跳过/成功,但不会失败。这基本上与 NUnit Timeout 相反属性。 该问
下面的查询是我之前使用的...但是我想结合这两个查询以提高性能 select a, b, c from table1 where d LIKE 'xxx' and f like 'yyyy
当我运行这段代码时出现错误, at javaapplication1.JavaApplication1.bigger(JavaApplication1.java:32) (反向警告),但是我已经
使用 SQL。我正在尝试列出所有城市的人口总数少于 10 万的每个国家/地区的名称。 下面的代码为我提供了拥有超过 100 000 人的城市的每个国家/地区,因此根据术语,我试图“反转”输出以列出此时
我正在创建一个 iOS 用户界面,允许用户在现有图像中选择一个矩形,将该矩形的角拖动到所需的大小。我现在有四个自定义 UIButton(30% alpha)和一个在四个角按钮之间绘制虚线的自定义 Vi
我需要更改现有的映射,将键交换为值,将值交换为键。由于我的映射中的键有重复值,因此我无法使用下划线库的 _.invert() 。 function map() { return {
我想以最好的 numpythonic 方式解决的问题是:我有一个二维索引列表 A,例如: A = [(0, 3), (2, 2), (3, 1)] 我的目标是现在得到一个数组 [[H H H 0],
我有一个二值图像,尺寸为 64x63,其中每个像素都是 1 或 0。 import struct from PIL import Image import numpy ... i1 = Image.f
假设我有一个整数数组 A 使得 A[i] = j,我想“反转它”;也就是说,创建另一个整数数组 B 使得 B[j] = i。 这对于任何语言的线性时间程序来说都是微不足道的;这是一个 Python 示
我是一个非常没有经验的 C 学习者,我在这段代码中收到了警告,它应该在调用时反转作为命令的第一个参数传递的字符串(在 Linux Ubuntu 中编程)。 警告是:14:9: warning: ass
MySQL (Innodb) 使用倒排索引还是正向索引? 来自文章What's the difference between an inverted index and a plain old ind
本文主要是利用Python的第三方库Pillow,实现单通道灰度图像的颜色翻转功能。 ?
我是一名优秀的程序员,十分优秀!