gtkmm绘制单个像素 [英] gtkmm drawing single pixels
问题描述
请参考文档中的示例Gtkmms GdkRGB :
#include <gtk/gtk.h>
#define IMAGE_WIDTH 256
#define IMAGE_HEIGHT 256
guchar rgbbuf[IMAGE_WIDTH * IMAGE_HEIGHT * 3];
gboolean on_darea_expose (GtkWidget *widget,
GdkEventExpose *event,
gpointer user_data);
int
main (int argc, char *argv[])
{
GtkWidget *window, *darea;
gint x, y;
guchar *pos;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
darea = gtk_drawing_area_new ();
gtk_widget_set_size_request (darea, IMAGE_WIDTH, IMAGE_HEIGHT);
gtk_container_add (GTK_CONTAINER (window), darea);
gtk_signal_connect (GTK_OBJECT (darea), "expose-event",
GTK_SIGNAL_FUNC (on_darea_expose), NULL);
gtk_widget_show_all (window);
/* Set up the RGB buffer. */
pos = rgbbuf;
for (y = 0; y < IMAGE_HEIGHT; y++)
{
for (x = 0; x < IMAGE_WIDTH; x++)
{
*pos++ = x - x % 32; /* Red. */
*pos++ = (x / 32) * 4 + y - y % 32; /* Green. */
*pos++ = y - y % 32; /* Blue. */
}
}
gtk_main ();
return 0;
}
gboolean
on_darea_expose (GtkWidget *widget,
GdkEventExpose *event,
gpointer user_data)
{
gdk_draw_rgb_image (widget->window, widget->style->fg_gc[GTK_STATE_NORMAL],
0, 0, IMAGE_WIDTH, IMAGE_HEIGHT,
GDK_RGB_DITHER_MAX, rgbbuf, IMAGE_WIDTH * 3);
return TRUE;
}
但是他们说" gdk_draw_rgb_image
已过时,不应在新编写的代码中使用."
But they say that "gdk_draw_rgb_image
is deprecated and should not be used in newly-written code."
我想在一个像素阵列中有一个图像,我可以在其中直接操纵像素.
I would like to have an image in an array of pixels, where I can directly manipulate the pixels.
基本上,我只是想绘制"我想修改的像素阵列.开罗是一个很好的工具,但不适合我的目的.因此, rectangle
不是一个选择.
Basically, I just would like to "draw" an array of pixels I would like to modify before. Cairo is a nice tool, but not suitable for my purpose. Therefore, rectangle
is not an option.
这不可能了吗?
好吧,我之前提到的示例是可行的,但是我不希望对新代码使用不赞成使用的库.
Well, the example I mentioned before works, but I prefer not to use deprecated libraries for new code.
那我还能怎么画像素?这是一个gtk示例.我们正在使用GtkMM,我想知道是否与此等效.
How else can I draw my pixels then? And this is a gtk example. We're using GtkMM and I would like to know whether there's an equivalent to this.
非常感谢和问候
推荐答案
您必须使用开罗.
在GDK 3中已弃用并删除了所有GDK绘图功能.
All GDK drawing functions are deprecated and removed in GDK 3.
您可以使用 GdkPixbuf
http://developer.gnome.org/gdk3/stable/gdk3-Cairo-Interaction.html .
You can use a GdkPixbuf
http://developer.gnome.org/gdk-pixbuf/unstable//gdk-pixbuf-The-GdkPixbuf-Structure.html#GdkPixbuf with Cairo interaction functions gdk_cairo_set_source_pixbuf
and gdk_cairo_rectangle
http://developer.gnome.org/gdk3/stable/gdk3-Cairo-Interaction.html.
这篇关于gtkmm绘制单个像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!