我目前正在开发一个应用程序,它使用视频投影仪来创建类似于真实激光的效果。什么我试图存档一个非常好的例子可以在YouTube上看到这里。
基本上,该应用程序需要绘制各种颜色的简单移动形状。我有一个使用 pycairo 的非常复杂的设置,允许基元通过一组修改器来改变位置、缩放和旋转。这提供了很大的灵活性。
不幸的是,pycairo 在绘制虚线圆圈方面似乎很慢。我试着像这样画 30 个圆圈:
# setup, transforms...
# Example color-scheme:
self._colors = [(0.0, 1.0, 0.0)]
# drawing dashes one after another
for count, color in enumerate(self._colors):
cr.set_dash(dash_len, self._dash_len * count)
cr.set_source_rgb(color[0], color[1], color[2])
cr.arc(0, 0, self.radius(), 0, 2 * math.pi)
cr.stroke()
Run Code Online (Sandbox Code Playgroud)
整个事情看起来像这样。使用 Core2Duo 无法在 800x600 分辨率下维持 25fps。
有没有更快的方法来画圆圈?质量真的不是问题。
谢谢你的帮助!
我目前正在将一个非常基本的图库应用程序从PHP移植到Go.此应用程序具有自动生成缩略图和每个图像的中型版本.
在PHP中,我使用了GD,因为它附带了它并且工作得非常好.(代码在问题的最后).我想我可以在Go中复制它,并go-gd从https://github.com/bolknote/go-gd找到(再次,代码在最后).它可以工作,但它大约慢10倍(使用测量time wget $URL).从10 MP图像生成1024x768版本的PHP实现大约需要1秒,而Go-Code需要大约10秒.
有没有什么方法可以加速Go或任何其他图像处理库,Go实现缩放和卷积,同时速度相当快?
public function saveThumb($outName, $options) {
$this->img = imagecreatefromjpeg($filename);
if (!is_dir(dirname($outName))) {
mkdir(dirname($outName), 0777, true);
}
$width = imagesx($this->img);
$height = imagesy($this->img);
if ($options["keep_aspect"]) {
$factor = min($options["size_x"]/$width, $options["size_y"]/$height);
$new_width = round($factor*$width);
$new_height = round($factor*$height);
} else {
$new_width = $options["size_x"];
$new_height = $options["size_y"];
}
// create a new temporary image
$tmp_img = imagecreatetruecolor($new_width, $new_height);
// copy and resize old image into new image
imagecopyresampled($tmp_img, $this->img, 0, 0, …Run Code Online (Sandbox Code Playgroud)