gtkmm绘制单个像素

发布于 2024-12-12 15:04:18 字数 1839 浏览 3 评论 0原文

参考 Gtkmms GdkRGB 文档中的示例< /a>:

#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 已弃用,不应在新编写的代码中使用。”

我想要一个像素数组中的图像,我可以在其中直接操作像素。

基本上,我只是想“绘制”我之前想要修改的像素数组。 Cairo 是一个不错的工具,但不适合我的目的。因此,矩形不是一个选项。

这已经不可能了吗?

好吧,我之前提到的示例是有效的,但我不喜欢在新代码中使用已弃用的库。

那么我还能如何绘制像素呢? 这是一个 gtk 示例。我们正在使用 GtkMM,我想知道是否有与之等效的东西。

非常感谢和最诚挚的问候

Refering to the example on the Documentation for 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;
}

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.

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.

Isn't this possible anymore?

Well, the example I mentioned before works, but I prefer not to use deprecated libraries for new code.

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.

Many Thanks and best regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

平安喜乐 2024-12-19 15:04:20

必须使用开罗。

所有 GDK 绘图函数在 GDK 3 中均已弃用并删除。

您可以使用 GdkPixbuf http://developer.gnome.org/gdk-pixbuf/unstable//gdk-pixbuf-The-GdkPixbuf-Structure.html#GdkPixbuf 与 Cairo 交互函数 gdk_cairo_set_source_pixbuf 和 <代码>gdk_cairo_rectangle http://developer.gnome.org/gdk3/stable/gdk3-Cairo-Interaction .html

You have to use cairo.

All GDK drawing functions are deprecated and removed in GDK 3.

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.

风吹雪碎 2024-12-19 15:04:20

您可以构建自己的“put_pixels(.. .)" 功能类似于 此处
您将需要对像素缓冲区进行操作。

我也用过这个方法。

You can build your own "put_pixels(...)" function like discribed here.
You will need to operate on the pixel-buffer.

I also used this approach.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文