我正在尝试使用 cairo 绘制一些弧线,但 gcc 警告我gdk_cairo_create() is deprecated. Use gdk_window_begin_draw_frame() and gdk_drawing_context_get_cairo_context() instead。
为了解决这个问题,我做了一些研究,发现对于 gdk_window_begin_draw_frame() 我需要“GdkWindow”。我一直在我的窗口中使用 GtkWidget,所以我需要将“GtkWidget”转换为“GdkWindow”,但 gtk_widget_get_window() 返回NULL 并导致段错误。
#include <gtk/gtk.h>
#include <cairo.h>
void main(int argc , char **argv){
gtk_init(&argc , &argv);
GtkWidget *win;
GdkWindow *gdkwin;
GdkDrawingContext *dc;
cairo_region_t *region;
cairo_t *cr;
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
region = cairo_region_create();
gdkwin = gtk_widget_get_window(GTK_WIDGET(win));
//Here gdkwin should contain a GdkWindow but it's NULL.
gc = gdk_window_begin_draw_frame(gdkwin , (const cairo_region_t*)®ion);
...
...
Run Code Online (Sandbox Code Playgroud)
这是运行时错误:
(a.out:6852): Gdk-CRITICAL **: 23:53:06.042: gdk_window_begin_draw_frame: assertion 'GDK_IS_WINDOW (window)' failed …Run Code Online (Sandbox Code Playgroud) 我想保存以下情节:
library(ggplot2)
myplot <- ggplot(iris) +
geom_point(aes(x = Sepal.Width, y = Sepal.Length)) +
ylab(expression(~delta^13*C~"[\211]"))
ggsave(myplot,
filename = "myplot.png",
type = "cairo")
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
Error in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
Metric information not available for this family/device
Run Code Online (Sandbox Code Playgroud)
问题一定是表达式和 unicode 的组合,因为这两者可以工作:
myplot <- ggplot(iris) +
geom_point(aes(x = Sepal.Width, y = Sepal.Length)) +
ylab("[\211]")
myplot <- ggplot(iris) +
geom_point(aes(x = Sepal.Width, y = Sepal.Length)) +
ylab(expression(~delta^13*C))
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?
编辑:我想打印“千分之一”符号。显然它的unicode是U2030,我错误地认为“\211”是一个unicode,但一定是别的东西。
编辑2:与此同时,我发现这个问题也有类似的问题。在那里,一个建议是用 保存情节encoding = "MacRoman",不幸的是这对我不起作用:
Error in png_dev(..., res = …Run Code Online (Sandbox Code Playgroud) 我必须从开罗表面像素数据填充 ffmpeg AVFrame->data。我有这个代码:
/* Image info and pixel data */
width = cairo_image_surface_get_width( surface );
height = cairo_image_surface_get_height( surface );
stride = cairo_image_surface_get_stride( surface );
pix = cairo_image_surface_get_data( surface );
for( row = 0; row < height; row++ )
{
data = pix + row * stride;
for( col = 0; col < width; col++ )
{
img->video_frame->data[0][row * img->video_frame->linesize[0] + col] = data[0];
img->video_frame->data[1][row * img->video_frame->linesize[1] + col] = data[1];
//img->video_frame->data[2][row * img->video_frame->linesize[2] + col] = data[2];
data += …Run Code Online (Sandbox Code Playgroud) 我有一个wx.ScrolledWindow使用的地方cairo.我已经实现了缩放功能,现在可以重绘整个内容.但是由于最多可绘制200条曲线,因此我应考虑采用更高效的解决方案.
我想到了这些:
还有其他可能性,并且:最佳解决方案是什么?
非常感谢
我使用brew在OSX 10.7.5服务器上安装了R:
brew install R
Run Code Online (Sandbox Code Playgroud)
一切看起来都那么好,但是开罗没有工作:
> svg(tempfile())
Warning messages:
1: In svg(tempfile()) :
unable to load shared object '/usr/local/Cellar/r/2.15.2/R.framework/Resources/library/grDevices/libs//cairo.so':
dlopen(/usr/local/Cellar/r/2.15.2/R.framework/Resources/library/grDevices/libs//cairo.so, 6): image not found
2: In svg(tempfile()) : failed to load cairo DLL
Run Code Online (Sandbox Code Playgroud)
共享对象文件似乎完全丢失:
id-86-243:Resources jeroen$ ls -ltr library/grDevices/libs/
total 488
-rwxrwxr-x 1 jeroen admin 245764 Dec 22 17:03 grDevices.so
Run Code Online (Sandbox Code Playgroud)
我很少使用OSX,所以我不太确定这是否是R的特定分布中的错误,或者如果我在构建它时做错了什么?
我最近在Haskell中完成了X11编程的第一步,现在我想用Cairo/Pango绘制文本.我发现了一些C教程,似乎我需要使用创建一个Xlib表面cairo_xlib_surface_create().开罗
有一个Haskell包装器,但是这个函数的包装器似乎缺失了.
但是,由于表面的文档提到了Xlib后端,因此似乎还有一种方法可以直接在Ca11的X11窗口上绘制.
但我找不到任何进一步的信息.
我设法找到这段代码片段并用Cairo编译:
#define LIBCAIRO_EXPORTS
#include <cairo/cairo.h>
#include <cairo/cairo-win32.h>
int main(int argc, char** argv)
{
cairo_surface_t *surface;
cairo_t *cr;
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 240, 80);
cr = cairo_create (surface);
cairo_select_font_face (cr, "serif", CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size (cr, 32.0);
cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
cairo_move_to (cr, 10.0, 50.0);
cairo_show_text (cr, "Hello, World");
cairo_destroy (cr);
cairo_surface_write_to_png (surface, "hello.png");
cairo_surface_destroy (surface);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如您所见,它创建一个带有"Hello World"文本的图像并将其保存在驱动器上.如何创建win32曲面并绘制到窗口?
我没有使用: cairo_win32_surface_create
它需要一个hdc,我不知道那是什么.我试着阅读一些教程,但似乎没有人会引导您打印到新窗口.
我找到了这个链接:http: //windrealm.org/cairo-gdi/
它有一个工作演示,但它使用int WINAPI WinMain.我不想用它.
我在nodejs上有一个函数,可以从许多图像中生成图像,然后从中生成pdf文件。我只尝试一张图片,但我需要添加更多图片,但这似乎不起作用
function HelperHandler() {
this.pdf = function(req, res, next) {
var doc = new PDFDocument;
mergeImages(function(err, image) {
if (err)
return res.json(err);
doc.image(image, 100, 100);
doc.output(function(string) {
res.contentType = "application/pdf";
res.send(string);
});
})
}
}
var mergeImages = function(callback) {
var Canvas = require("canvas")
, fs = require("fs");
fs.readFile(global.root_path + "/images/bg.jpg", function(err, data) {
if (err)
callback("error loading image");
else {
var canvas = new Canvas(408, 939)
, img = new Canvas.Image(data);
ctx = canvas.getContext("2d");
img.onload = function() {
ctx.drawImage(img, …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,再次链接SDL和cairo,我想在ubuntu上为win64交叉编译.我使用这篇优秀的博客文章来获取SDL交叉编译,并且我使用了另一篇博文来交叉编译zlib,libpng和libpixman.
但是,我现在在尝试编译我的最小测试程序时遇到链接器错误:
$ make cairotest.exe
x86_64-w64-mingw32-gcc -o cairotest.o -c cairotest.c -I/usr/x86_64-w64-mingw32/include/SDL2 -Dmain=SDL_main -I/home/jshaw/x86_64-w64/include/cairo -I/home/jshaw/x86_64-w64/include/pixman-1 -I/home/jshaw/x86_64-w64/include/libpng16
x86_64-w64-mingw32-gcc -o cairotest.exe cairotest.o -L/usr/x86_64-w64-mingw32/lib -lmingw32 -lSDL2main -lSDL2 -mwindows -L/home/jshaw/x86_64-w64/lib -lcairo
collect2: error: ld returned 1 exit status
Makefile:13: recipe for target 'cairotest.exe' failed
Run Code Online (Sandbox Code Playgroud)
我应该提一下,如果我只使用没有任何开放代码的SDL2,这个测试程序可以正常工作,所以我怀疑我交叉编译的cairo库有问题.我该如何诊断问题呢?
我在使用GTK和Cairo显示Alpha透明度时遇到问题。我尝试显示此图像1
如果我进行Alpha混合自我,则一切正常。
如果我将Alpha值直接传递给开罗,则阴影似乎可以渲染得很好,但是发光效果已损坏。
这是开罗1.14.2中的错误,还是我错过了一些东西?
//Need deprecated API to get background color
GdkColor color = gtk_widget_get_style(widget)->bg[GTK_STATE_NORMAL];
Pixel color_blend
{
uint8_t(255*color.red/65535.0f)
,uint8_t(255*color.green/65535.0f)
,uint8_t(255*color.blue/65535.0f)
,255
};
while(ptr!=ptr_end)
{
// TODO: Interpolate
auto row_src=size_t(row*factor);
auto col_src=size_t(col*factor);
auto alpha=ptr_src[row_src*width_in + col_src].v3/255.0f;
*ptr=
{
// Using manual alpha blend works
uint8_t(alpha*ptr_src[row_src*width_in + col_src].v2 + (1-alpha)*color_blend.v2)
,uint8_t(alpha*ptr_src[row_src*width_in + col_src].v1 + (1-alpha)*color_blend.v1)
,uint8_t(alpha*ptr_src[row_src*width_in + col_src].v0 + (1-alpha)*color_blend.v0)
,255
/* This appears to be broken
ptr_src[row_src*width_in + col_src].v2
,ptr_src[row_src*width_in + col_src].v1
,ptr_src[row_src*width_in + col_src].v0
,ptr_src[row_src*width_in + col_src].v3*/
}; …Run Code Online (Sandbox Code Playgroud)