我对cairo库有疑问.
我下载了一张图片,然后把它放入缓冲存储器中.在cairo中是否有任何解决方案从内存中的数据加载图像?
谢谢
我有一个使用Cairo 图像表面的小型 PyGI 项目,然后我使用表面图案进行缩放并在 Gtk.DrawingArea 上渲染。
我想将缩放版本写入PNG 文件。我试图用Surface.write_to_png()从原始表面写入,但它只写入原始(即非缩放)大小,所以我被困在那里。
然后我想我也许可以从 Gtk.DrawingArea 获取渲染图像并将其写入磁盘,但我还没有找到如何在 PyGI 中做到这一点(这似乎只能在 GTK+ 2 中实现 -将 gtk.DrawingArea 保存到文件)。所以我想弄清楚如何将缩放后的图像写入磁盘。
这是创建表面、放大并渲染它的代码:
def on_drawingarea1_draw (self, widget, ctx, data=None):
# 'widget' is a Gtk.DrawingArea
# 'ctx' is the Cairo context
text = self.ui.entry1.get_text()
if text == '':
return
# Get the data and encode it into the image
version, size, im = qrencode.encode(text)
im = im.convert('RGBA') # Cairo expects RGB
# Create a …Run Code Online (Sandbox Code Playgroud) 我在Ubuntu 10.04上使用gtkmm2.4.(因此我的示例包含on_expose_event()例程而不是on_draw()).似乎VBox中没有窗口引用on_expose_event()中的get_window().我必须添加它吗?
原始代码http://developer.gnome.org/gtkmm-tutorial/2.22/gtkmm-tutorial.html#sec-drawing-clock-example
我的代码是
test.h
#ifndef TEST_H
#define TEST_H
#include <gtkmm.h>
class TEST : public virtual Gtk::Window
{
private:
public:
TEST();
virtual ~TEST();
protected:
Gtk::VBox V; // Make V Box
Gtk::HBox H1; // Upper H Box
Gtk::HBox H2; // Lower H Box
class Clock : public virtual Gtk::DrawingArea
{
public:
Clock();
virtual ~Clock();
protected:
//Override default signal handler:
virtual bool on_expose_event(GdkEventExpose* event);
double m_radius;
double m_lineWidth;
bool onSecondElapsed(void);
Glib::RefPtr<Gdk::Window> m_refGdkWindow;
};
};
#endif // TEST_H
Run Code Online (Sandbox Code Playgroud)
test.cc
#include <ctime>
#include …Run Code Online (Sandbox Code Playgroud) 我想在Mac OSX Lion上为Cairo安装Python绑定,以便我可以将它们与Python 2.7的Apple版本一起使用.我倾向于使用Python模块等安装easy_install,但在这种情况下似乎不起作用:
$ sudo easy_install pycairo
Searching for pycairo
Reading http://pypi.python.org/simple/pycairo/
Reading http://cairographics.org/pycairo
Best match: pycairo 1.10.0
Downloading http://cairographics.org/releases/pycairo-1.10.0.tar.bz2
Processing pycairo-1.10.0.tar.bz2
error: Couldn't find a setup script in /tmp/easy_install-BYpm4Y/pycairo-1.10.0.tar.bz2
Run Code Online (Sandbox Code Playgroud)
Stack Overflow上的其他地方也有类似的问题,但答案并没有解释我在这里做错了什么.
这个问题与Python 2.6有关,接受的答案使用Macport而不是easy_install,而另一个答案似乎是建议使用我上面尝试的方法(失败):
这个问题涉及从源代码构建pycairo,我不想这样做:
我正在使用 c# 和 Cairo 创建一个 pdf 文件。我想制作一个多页的 pdf,但我找不到任何样本。我只找到了这个:http : //lists.cairographics.org/archives/cairo/ 2008-9月/014949.html
任何帮助或建议将不胜感激。
我正在尝试使用Xlib和Cairo制作屏幕截图,但是我不确定这样做的好方法,"stride"让我很困惑.
这是代码:
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <cairo.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
int main(int argc, char** argv) {
int x, y;
Display *disp;
Window root;
XWindowAttributes watts;
XImage *image;
cairo_surface_t *surface;
unsigned int width;
unsigned int height;
int stride;
disp = XOpenDisplay(NULL);
root = DefaultRootWindow(disp);
XGetWindowAttributes(disp, root, &watts);
width = watts.width;
height = watts.height;
image = XGetImage(disp, root, watts.x, watts.y, width, height, AllPlanes, ZPixmap);
stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, width);
unsigned char *data = malloc(width * …Run Code Online (Sandbox Code Playgroud) 我已经在服务器中安装了 cairo-devel。当我尝试以下行时:
sudo su - -c "R -e \"install.packages('Cairo', repos='http://cran.rstudio.com/')\""
我得到了一堆输出,但最相关的输出如下:
img-backend.c:82:13: warning: ‘image_save_page_jpg’ defined but not used [-Wunused-function]
static void image_save_page_jpg(Rcairo_backend* be, int pageno){
^
img-backend.c:96:13: warning: ‘image_save_page_tiff’ defined but not used [-Wunused-function]
static void image_save_page_tiff(Rcairo_backend* be, int pageno){
^
xlib-backend.c:34:74: fatal error: X11/Intrinsic.h: No such file or directory
#include <X11/Intrinsic.h> /*-> Xlib.h Xutil.h Xresource.h .. */
^
compilation terminated.
make: *** [xlib-backend.o] Error 1
ERROR: compilation failed for package ‘Cairo’
* removing ‘/usr/lib64/R/library/Cairo’
Run Code Online (Sandbox Code Playgroud)
我将如何解决这个问题?
我正在尝试使用 GTK3 库和 pycairo 在 python3 中制作一些简单的动画。
我一直试图找到简单的单文件示例但无济于事,但我确信它是可行的。
我找到的最接近的是:https://cairographics.org/cookbook/animationrotation/,但这是在 python2 中,库/依赖项完全不同。
有没有人能指点我一个体面的来源,或对上述代码的修改?
谢谢!
好吧,所以我使用cairo将SVG转换为openGL纹理的图像数据.
那部分有效.
但是现在我正在使用的纹理不会映射到我正在制作的四边形.它只是显示为一个空白方块.
有什么东西跟我正在调用的东西或是否有一些我忘记使用的秘密功能?
const int SCREEN_WIDTH = 1280;
const int SCREEN_HEIGHT = 720;
const int SCREEN_BPP = 32;
int frame = 0;
SDL_Event event;
bool quit;
GLuint texture[1];
int main(int argc, char *argv[]) {
g_type_init();
rsvg_init();
SDL_Surface *screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_OPENGL );
SDL_WM_SetCaption ("Cairo", NULL);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
/*2D stuff - it worked here
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1, 1 );
glMatrixMode( …Run Code Online (Sandbox Code Playgroud) cairo ×9
gtk ×4
pycairo ×3
c++ ×2
macos ×2
python ×2
c ×1
c# ×1
centos7 ×1
easy-install ×1
gtkmm ×1
linux ×1
opengl ×1
pangocairo ×1
png ×1
pygobject ×1
pygtk ×1
python-3.x ×1
r ×1
screenshot ×1
shiny-server ×1
x11 ×1
xlib ×1