- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
你好我想用java画线,刷新率为60fps:
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.Group;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
import javafx.animation.Timeline;
import javafx.animation.KeyFrame;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.util.Duration;
import javafx.event.EventHandler;
import javafx.event.ActionEvent;
import javafx.event.EventType;
import javafx.scene.paint.Color;
public class Example extends Application
{
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage theStage)
{
Group root = new Group();
Scene theScene = new Scene( root );
theStage.setScene( theScene );
Canvas canvas = new Canvas( 512, 512 );
root.getChildren().add( canvas );
GraphicsContext gc = canvas.getGraphicsContext2D();
Timeline gameLoop = new Timeline();
gameLoop.setCycleCount( Timeline.INDEFINITE );
final long timeStart = System.nanoTime() -10000000000000l;
KeyFrame kf = new KeyFrame(
Duration.seconds(0.017), // 60 FPS
new EventHandler<ActionEvent>()
{
public void handle(ActionEvent ae)
{
// Clear the canvas
gc.clearRect(0, 0, (int)canvas.getWidth(),(int)canvas.getHeight());
for(int i=0;i<(int)(canvas.getWidth()/10);i++) {
//gc.setS
for(int j=0;j<10;j++)
{
if(j==0){gc.setStroke(Color.web("#000000"));}
else{gc.setStroke(Color.web("#aaaaaa"));}
gc.moveTo(j+i*10, 110);
gc.lineTo(j+i*10, canvas.getHeight());
//using gc.stroke instead of moveTo and lineTo works with good performance,but i need 1px width
//gc.strokeLine(j+i*10, 110, j+i*10, canvas.getHeight());
}
}
gc.stroke();
}
});
gameLoop.getKeyFrames().add( kf );
gameLoop.play();
theStage.show();
theScene.widthProperty().addListener(observeable -> {
canvas.setWidth(theScene.getWidth());
});
}
}
然而,这太慢了,程序会崩溃。使用“strokeLine()”它运行正常,但我真的需要绘制宽度为 1px 的线条。
我想我必须在绘制完整场景之前将绘图保存在缓冲区中。但是我读到 javafx 正在向您隐瞒低级内容。那么还有另一种绘制 1px 线的方法吗?
最佳答案
您不会在每次迭代时将路径重置为空。因此,路径笔划在累积:第一次迭代有 500 行,第二次有 1000 行,第三次有 1500 行,等等。
你需要
gc.beginPath();
在调用 gc.clearRect(...);
之后
关于Java lineTo() 非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34998682/
我试图根据点'数组中的坐标绘制线条,但当我调用此方法时,它在线条中显示以下错误。当我写例如console.log(points[1][1]) 它向我显示了该元素。有人能指出我在这里想念的东西吗? "U
你好我想用java画线,刷新率为60fps: import javafx.application.Application; import javafx.stage.Stage; import java
我有一个来自Inkscape,Illustrator或任何其他应用程序的SVG文件。我想将形状转换为lineto,moveto,curveto格式。 我想要的是这样的: ./Appname svgfi
我目前正在 Android Studio 上学习 Canvas,我不太确定使用正确的标题,但我一直在研究如何在使用 Seekbar 拖动红点时控制三角形位置。以下是详细信息 下面是我成功绘制三角形的代
我需要随机化形状的坐标。我知道我需要以某种方式介绍 Math.floor(Math.Random * num);在那里排队,但我所做的一切似乎都不起作用。 这是我要随机化的填充了坐标的 block 。
我刚刚开始学习 C++。我想要做的就是画一条线到指定的坐标,它作为方法的输入。我使用 MoveToEx 在每个循环中设置起点(在循环中使用不同的参数调用此函数)并给出我想要绘制车道的坐标。 关于如何使
有人可以帮助我了解 path.lineTo(x,y) 的实际工作原理吗?我正在尝试在手指画类型的应用程序中绘制一条简单的直线。这是我试过的一个例子: mPath.reset()
我正在尝试使用两个for循环绘制网格,一个用于绘制10条垂直线,另一个用于绘制10条水平线。像这样: for(var i=1;i 这确实很奇怪。我测试了你在这里写的所有内容,结果是一样的。现在我拼命打
我是 JavaScript 新手! 如何将变量分配给当前的 xy 坐标,以便我可以使用相对位置来绘制线条?尝试用键盘进行 eclipse 刻草图。上、下、左、右箭头键...使用 JS、CSS 和 HT
假设我有以下 JavaScript 代码: var canvas = document.getElementById('myCanvas'); var ctx = canvas.getContext(
function TrackGraphic(model, canvas) { //TrackModel this._model = model; this.draw = fun
这种情况不好解释,我用一张图来说明: 创建的第一个形状内的像素变亮。用黑色清除屏幕,绘制红色和绿色框,然后绘制路径。到目前为止,我发现的唯一修复方法是将框的线宽设置为 2 像素,原因已概述 here
有没有办法为 TCanvas.LineTo 方法设置 lineends 的样式?它似乎默认为圆角末端,当 Pen.Width 设置为较大值(例如 9)时,对于不同颜色的一行中的多条线来说,这看起来非常
我尝试使用 HTML5 Canvas 制作动画,在其中绘制 3 个片段的位置,每个片段用一个圆圈连接起来。 每个圆的位置由 (x1,y1)、(x2,y2) 和 (x3,y3) 确定。 这是我的代码片段
我正在一个单独的项目中,试图从炮塔到敌人画一条线。但是我希望这条线保持在炮塔边界之内,而不是一直延伸到敌人。我在下面的代码段中找到了一个较小的示例。 请彻底回答,因为我绝对不是专家。非常感谢!谢谢。
我一直在查看 Emanuele Feronato 的字符串避免器代码(下面的代码和链接)并尝试对其进行调整,以便当字符串与自身相交时 - 形成一个闭环 - 它只填充该区域 see image .我的数
我目前正在尝试在我的 Canvas speechbubble 元素下绘制一个箭头。 我的问题: 箭头的右侧似乎比左侧长得多。 我尝试了什么: 我尝试通过以下方式创建箭头: ctx.moveTo(x,
我创建了一个扩展 Shape 的类,以便为我的按钮背景绘制自定义形状(带切角的矩形)。我遇到的问题是画成对角线的线看起来比直线粗得多: 如何使边框始终保持一致的宽度?我尝试将抗锯齿设置为 true/f
主题说明了一切:您可以将负数传递给 HMTL5 Canvas 中的绘图基元吗? 例如,如果我转换为 (100,100),我可以使用坐标 (-25,-25) 绘制一个矩形或直线吗?使用 lineTo 进
我有一个简单的 Canvas 绘图应用程序。 有时 lineTo() 命令会生成一条坐标较少的线,并且绘图有很多边: 我正在使用最新的 firefox,是因为连接不好还是我的电脑很忙?有解决办法吗?这
我是一名优秀的程序员,十分优秀!