- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 Android 应用程序中,我有一个可以缩放和平移的 View 。在那个观点上,我想为以下几点画一条线。但是根本没有显示路径。我想知道这是否与点列表中的负数或大数有关。
{"x":-317,"y":-744},{"x":50,"y":-702},{"x":394,"y":-663},{"x":718,"y":-626},{"x":1023,"y":-592},{"x":1310,"y":-560},{"x":1581,"y":-529},{"x":1837,"y":-500},{"x":2079,"y":-472},{"x":2951,"y":198},{"x":5997,"y":4780},{"x":4064,"y":4143},{"x":2686,"y":3689},{"x":1654,"y":3348},{"x":852,"y":3084},{"x":211,"y":2873},{"x":-312,"y":2700},{"x":-748,"y":2556},{"x":-895,"y":2213},{"x":-574,"y":569},{"x":-317,"y":-744}]}
这是代码 fragment 。
private final Paint paintStrokeArea = new Paint(Paint.ANTI_ALIAS_FLAG);
private Point[] viewArea = ...
public MyView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
paintStrokeArea.setColor(Color.WHITE);
paintStrokeArea.setStyle(Style.STROKE);
paintStrokeArea.setStrokeWidth(4.5f);
paintStrokeArea.setStrokeJoin(Join.MITER);
paintStrokeArea.setPathEffect(null);
}
public onDraw(Canvas) {
if (viewArea != null)
renderViewArea(viewArea, canvas, paintStroke);
}
public static void renderViewArea(Point[] area, Canvas canvas, Paint paint) {
if (area == null || canvas == null || paint == null)
return;
boolean first = true;
Path path = new Path();
Point last = new Point();
for (Point current : area) {
if (first) {
first = false;
} else {
path.moveTo(last.x, last.y);
path.lineTo(current.x, current.y);
}
last.set(current.x, current.y);
}
if (!first)
canvas.drawPath(path, paint);
}
最佳答案
this post 中描述了同样的问题.根据答案,出现问题是因为 drawPath 是在 CPU 中通过将其渲染成位图然后传输到 GPU 中来完成的。因为我的路径太大,位图无法渲染(发送到)GPU。最好使用 drawLines,因为它直接使用 GPU。这是我封装的辅助类。
package eu.level12.tools;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
/**
* Provides several static methods for drawing onto Android's canvas.
* Hardware-accelerated methods are named with the prefix render while others
* begin with draw.
*
* @author Matthias Heise
*
*/
public final class DrawingTools {
/**
* Draws the line specified by the given path using hardware-accelerated
* method Canvas.drawLines. Has no effect if either argument is null or if
* the line consists of less than two points.
*
* @param path
* A path of points that specifies the line.
* @param canvas
* The canvas onto which the line should be drawn.
* @param paint
* The paint argument that specifies how the line is drawn.
*/
public static void renderLine(Point[] path, Canvas canvas, Paint paint) {
if (path == null || canvas == null || paint == null || path.length <= 1)
return;
final float[] lines = new float[(path.length - 1) * 4];
int index = 0;
final Point last = new Point();
boolean first = true;
for (Point current : path) {
if (first) {
first = false;
} else {
// start point
lines[index] = last.x;
lines[index + 1] = last.y;
// end point
lines[index + 2] = current.x;
lines[index + 3] = current.y;
index += 4;
}
last.set(current.x, current.y);
}
if (!first)
canvas.drawLines(lines, paint);
}
}
关于android - Canvas : Path with negative and large positive numbers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23152843/
好吧,虽然模式 [abc] 匹配单个字符 a、b 或 c 时,模式 [^abc] 匹配任何不是的给定字符 a、b 或c. 现在,如果我在上面的语句中用 string 替换 character,如果我还
我正在学习 Haskell atm,现在我找到了这个功能 const const (negate 1) (negate 2) 3 这个函数的结果是 -2 .我不明白为什么结果不是 -2。 const
我可以有 /[abcd]/、/(ab|cd)/ 和 /[^wxyz]/。为什么不是 /(^wx|yz)/ Apparently您可以通过简单地将功能与其他功能组合在一起来实现完全相同的效果,如下所示:
我正在尝试在我的 C++ 14 代码中执行一个简单的操作 pow(-0.89,-0.67),它给出了一个 NaN 作为结果。在 SciLab 中执行相同操作时,结果为 -1.08。在 C++ 中有什么
我又在与正则表达式作斗争了。我一直在尝试添加使用转义字符来转义自定义标记,例如 至 和 至 .在乔治的帮助下,here , 在尝试转义方法之前,以下表达式会产生所需的结果。 ('This is a
我使用三个值(=页数)A , B , C对于属性(property)is of type . 某些页面只有一个值 is of type ,某些页面具有所有三个值。 我想要#ask对于类型为 A 的页面
我正在尝试使用普罗米修斯数据源在 Grafana 中绘制条形图。 我的简单查询如下所示: max_over_time(energy_monitor_watthour_today[1d]) 我将 Gra
我正在尝试使用 if GNU 中的函数(与条件语句之一相反)make如果未定义特定变量,则为了将单词添加到列表中。我最终这样做的方法是将第二个参数留空,同时提供第三个参数,如下所示: FOO := b
以下程序应打印数组元素的总和是正数还是负数: #include #define ARR_SIZE 5 int main() { int array[ARR_SIZE] = {1,-2,3,4,
我试图在公式中替换所有缺少前面零的 float 。例如: “4+.5”应该变成:“4+0.5” 现在我读到 JavaScript 不支持向后看,那么我该如何实现呢?当前面有数字时,以下代码也会替换:
我有这个 64x64 二维数组 该阵列的数据可在此处下载 - http://m.uploadedit.com/ba3s/1494223164755.txt 现在,我想复制这个数组,其中具有最高值的区域
我在研究 String 及其构造函数时发现了一些我无法解释的行为。 我创建了以下方法 public static String negate(String s) { byte[] b = s.
我在我的应用程序的 Crashlytics 中看到了这次崩溃。我不知道哪里出了问题。 有人对为什么会发生这种崩溃有任何建议吗? Fatal Exception: java.lang.IllegalAr
我有一些异常值的数据集,例如以下 x <- rnorm(1000,0,20) x <- c(x, 500, -500) 如果我们以此绘制在线性x轴刻度上,我们将看到 histogram(x) 我想出了
tl;dr:我该如何做类似下面编写的代码的事情: def notFunctor[M[_] : Not[Functor]](m: M[_]) = s"$m is not a functor" 'Not[
我有一个程序可以替换文件中的内容。但是却导致了IO异常,我不知道我哪里逻辑错了? 代码如下: import java.io.File; import java.io.RandomAccessFile;
我正在验证整数是否为零或更大。将需求描述为“零或更大”感觉过于冗长。说“非负面”会引入负面语言,我会尽量避免。 在描述必须为零或更大的值时,您使用什么简洁的描述符? 最佳答案 positiveValu
我使用的是tinyMCE版本3,我使用的是富文本编辑器,它会在输入时计算剩余的字符数。由于 maxLength 属性不适用于tinyMCE3。我已经以这种方式进行了硬编码,但它也计算了空白字符
下面的示例在调用look_back_1()或look_back_2()时应该崩溃。原因:当对无符号变量求反时,结果应保持无符号。 #include int look_back_1(int *arr,
虽然我阅读了大量有关该主题的文章(特别是使用环视),但我不明白是否可以使用正则表达式解决这种更一般的情况。 设置: 1) 在 中传递了一个输入正则表达式2) 输入正则表达式嵌入到负正则表达式中,这样
我是一名优秀的程序员,十分优秀!