سؤال

أنا أخلق برنامج رسم صغير في مونو GTK # واستخدام مكتبة الرسومات القاهرة.أنا الترميز وتجميع نظام ماكوس X.لدي كائن جميل وضعته في Pixbuf في وقت معين ثم استرجعه لاحقا في كائن جميل!الفكرة هي أن تأخذ "لقطة" للصورة في الرسم القابل للشرح ثم تعادلها فوقها.

المشكلة هي أنه عندما أضع Pixbuf مرة أخرى في الرشوة، تبدو غامضة، كل الأصفر مع المشارب ويبدو أنه جزء من الصورة مفقود.

تحديث: ركضت البرنامج على أجهزة Linux و Windows الخاصة بي وهناك يعمل بلا عيوب!لذلك هذا الخطأ هو فقط على ماكوس X. إليك الرمز: giveacodicetagpre.

سيكون موضع تقدير كبير إذا كان شخص يعرف ما يحدث هنا ويمكن أن يشيرني في الاتجاه الصحيح لإصلاحه.

هل كانت مفيدة؟

المحلول

I triggered the same problem in this manner:

gw = gtk_widget_get_window(GTK_WIDGET(GLOBALS->mainwindow));
if(gw)
    {       
    gdk_drawable_get_size(gw, &w, &h);
    cm = gdk_drawable_get_colormap(gw);
    if(cm)
            {
            dest = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, w, h);
            if(dest)
                    {
                    dest2 = gdk_pixbuf_get_from_drawable(dest, gw, cm, 0, 0, 0, 0, w, h);
                    if(dest2)
                            {
                            succ = gdk_pixbuf_save (dest2, *GLOBALS->fileselbox_text, "png", &err, NULL);
                            }
                    }
            }
    }

The gdk_pixbuf_get_from_drawable() function when the source drawable is a Quartz window has issues, specifically in how _gdk_quartz_image_copy_to_image() services it. In short, 256 bit vertical strips are converted but the conversion routine assumes the pixels are 24-bit RGB rather than 32-bit RGBA. The following patch fixed the problem for me:

--- gtk+/gdk/quartz/gdkimage-quartz.c   2011-12-03 14:24:03.000000000 -0600
+++ gtk+664894/gdk/quartz/gdkimage-quartz.c     2013-10-15 18:52:24.000000000 -0500
@@ -150,6 +150,10 @@ _gdk_quartz_image_copy_to_image (GdkDraw
       data = [rep bitmapData];
       size = [rep size];

+      int bpr = [rep bytesPerRow];
+      int wid = size.width;
+      int bpx = bpr/wid;
+
      for (y = 0; y < size.height; y++)
        {
         guchar *src = data + y * [rep bytesPerRow];
@@ -158,12 +162,15 @@ _gdk_quartz_image_copy_to_image (GdkDraw
            {
              gint32 pixel;

+              if (bpx == 4) // fix gdk_pixbuf_get_from_drawable "yellow stripes"
+                pixel = src[0] << 16 | src[1] << 8 | src[2];
+              else
              if (image->byte_order == GDK_LSB_FIRST)
                pixel = src[0] << 8 | src[1] << 16 |src[2] << 24;
              else
                pixel = src[0] << 16 | src[1] << 8 |src[2];

-             src += 3;
+             src += bpx;

              gdk_image_put_pixel (image, dest_x + x, dest_y + y, pixel);
            }

I don't know if this was fixed in future versions of the GTK OSX source. I use my own for producing binaries of gtkwave as I have some necessary patches that were seemingly never integrated into the jhbuild source tree long ago.

-Tony

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top