我有生成Cairo的代码ImageSurface,我这样暴露它:
def preview(...):
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
...
cherrypy.response.headers['Content-Type'] = "image/png"
return surface.get_data()
preview.exposed = True
Run Code Online (Sandbox Code Playgroud)
这不起作用(浏览器报告图像有错误).
我已经测试了它的surface.write_to_png('test.png')工作原理,但是我不确定将数据转储到什么内容以返回它.我猜一些像文件一样的对象?根据pycairo文档,get_data()返回一个缓冲区.我现在也尝试过:
tempf = os.tmpfile()
surface.write_to_png(tempf)
return tempf
Run Code Online (Sandbox Code Playgroud)
另外,最好是在内存中创建并保存此图像(就像我正在尝试做的那样)或将其作为临时文件写入磁盘并从那里提供服务?我只需要一次图像,然后就可以丢弃了.
我有一些音乐乐队的专辑标题.我想用一些将围绕图像角落的面具绘制它.所以,我在gimp中准备了这样的面具:

我正在使用白色面具,但在白色背景下它是隐形的.所以,这是渲染的代码:
# Draw album image
img = cairo.ImageSurface.create_from_png('images/album.png')
ctx.set_source_surface(img, posX, posY)
ctx.paint()
# Draw mask
ctx.set_operator(cairo.OPERATOR_DEST_IN)
img = cairo.ImageSurface.create_from_png('images/mask.png')
ctx.set_source_surface(img, posX, posY)
ctx.paint()
Run Code Online (Sandbox Code Playgroud)
如你所见,我已经习惯了OPERATOR_DEST_IN.我在此页面上找到的快速示例.
但是,当我在cairo中设置合成运算符时,我的程序中的一切都消失了:(.当我评论该行时,一切都没问题,但是掩码超出了我的图像.正确的方法是什么?
ps我正在使用python2,cairo库
当我删除合成操作符时,我看到(不要忘记真正的蒙版是白色的,在这种情况下专辑图像是暗的):

我想知道如何使用Cairo(在C中)直接在X11环境中的根窗口上绘制,以便制作小部件.我复制了tint2代码的一些部分,但是它非常庞大,而且我唯一的结果就是不满意.我很高兴有一个完整的工作示例代码,或至少一些提示或小程序来研究.感谢你们 !
我在开罗使用径向渐变,但我没有得到预期的结果.我得到的径向渐变比我预期的要模糊得多,我似乎无法摆弄颜色停止以获得理想的效果.这是代码:
cairo_pattern_t *pat;
pat = cairo_pattern_create_radial(100.0, 100.0, 0.0, 100.0, 100.0, 20.0);
cairo_pattern_add_color_stop_rgba(pat, 0, 0, 0, 0, 1);
cairo_pattern_add_color_stop_rgba(pat, 1, 0, 0, 0, 0);
Run Code Online (Sandbox Code Playgroud)
这是我正在谈论的图像.

我是cairo的新手,并且已阅读其网站上的教程/文档。现在,我可以制作线条,矩形,基本上可以渲染图像,但不能渲染文本。
我正在使用以下代码
cairo_select_font_face (cr, "monospace", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAl);
cairo_set_font_size (cr, 14);
cairo_set_source_rgb (cr, 1, 1, 1);
cairo_move_to (cr, 50, 50);
cairo_show_text (cr, "Print Something");
Run Code Online (Sandbox Code Playgroud)
有人可以指出我的错误吗?
我一直在尝试使用Inkscape为我的科学论文准备图稿图形.我使用LaTeX,我需要将我的数据准备为高质量的封装PostScript(EPS)图像.工单如下.首先,我使用matplotlib绘制我的图形的一部分并以EPS格式保存它们.其次,我启动Inkscape并导入EPS文件.使用Inkscape我组合一个数字,留下所需的对象,杀死不需要的东西,并添加一些标记.所以我曾经在Windows中使用CorelDraw时做过,但现在我在Linux上工作.
不幸的是,Inkscape会破坏EPS文件:它会改变颜色并且不会保存所有对象.在过去的几年里,我试图寻找解决方案,但我找不到人们的抱怨.投诉(在网上找到)与从svg导出到eps或返回时的"不正确的字体渲染"有关.(对我来说这不是问题 - 文本总是可以表示为曲线).
我目前在Mandriva Linux 2010工作并使用Inkscape版本0.47 r22583(2010年1月14日).在某处我读到这些问题可能是由一些过时的cairo版本引起的 - 我的是1.9.14.我花了很多精力去建造更新的开罗(1.12.14),但我还远没有达到目的.我在系统中共存的32位和64位库中感到困惑......
我将非常感谢任何有类似问题的人,并且可能会进一步向解决方案迈进.让我来说明问题.
对不起,我没有足够的声望点既不发布图片也不插入2个以上的链接,所以,请查看我的livejournal页面中的图片副本:
http://benkev.livejournal.com/1093.html
数字标题如下.
(1)以下是我想在一张图中合并的三个eps图像:
(2)这是我在Inkscape中导入图像并以SVG格式保存后得到的结果.注意颜色和分辨率失真.另外,我在感兴趣的特征周围绘制了三个红色圆圈.
(3)这是我将这个数字导出到EPS文件时得到的结果.人们可以注意到三个红色圆圈中的一个消失了:只留下两个圆圈!
谢谢!
我有一个只有freetype2和cairo库的系统.我想要实现的是:
不幸的是,文档并没有真正解释它应该如何完成,因为他们希望使用像Pango这样的更高级别的库.
我认为可能是正确的:创建一个缩放字体,cairo_scaled_font_create然后使用检索文本的字形cairo_scaled_font_text_to_glyphs.cairo_glyph_extents然后给出每个字形的范围.但是,我怎么能得到像字距调整和进步这样的东西呢?另外,我怎样才能获得每种字体的路径?
有关此主题的更多资源吗?这些功能是预期的方式吗?
编辑:此页面提供代码:https : //www.andrewheiss.com/blog/2017/09/27/working-with-r-cairo-graphics-custom-fonts-and-ggplot/
ggsave("test_cario.eps", device=cairo_ps)
ggsave("test_cario.pdf", device=cairo_pdf)
Run Code Online (Sandbox Code Playgroud)
但是,我想知道命令来自哪里。它们未包含在官方文档 ( https://ggplot2.tidyverse.org/reference/ggsave.html )的可能设备列表中。并且,cairo_png 不存在;相反, type="cairo-png" 是必要的,例如:
ggsave("test_cairo.png", type = "cairo-png")
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么争论是一次device = ""又一次type = ""?
我试过这样的代码
ggsave("model.eps", type = "cairo")
Run Code Online (Sandbox Code Playgroud)
或者
ggsave("model.eps", type = "cairo-ps")
或者
ggsave("model.eps", device = "cairo-ps")
但似乎没有任何效果。一般来说,是否可以使用 Cairo 图形设备通过 ggsave 创建 .eps 文件?如果是这样,如何?
尝试在 Django 中运行网站时遇到问题:
OSError: no library called "libcairo-2" was found
cannot load library 'libcairo.so.2': /lib/x86_64-linux-gnu/libfontconfig.so.1: undefined symbol: FT_Done_MM_Var
cannot load library 'libcairo.so': /lib/x86_64-linux-gnu/libfontconfig.so.1: undefined symbol: FT_Done_MM_Var
cannot load library 'libcairo.2.dylib': libcairo.2.dylib: cannot open shared object file: No such file or directory
cannot load library 'libcairo-2.dll': libcairo-2.dll: cannot open shared object file: No such file or directory
Run Code Online (Sandbox Code Playgroud)
虽然安装了包。
我已经安装了 weasyprint
pip3 install weasyprint
python -m pip install WeasyPrint
sudo apt-get install build-essential python3-dev python3-pip python3-setuptools python3-wheel python3-cffi libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 …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)