Beispiel #1
0
        private GdkPixBufBitmapSource LoadSourceFromGdkStream(IntPtr gdkStream)
        {
            IntPtr pixbuf = LibGdkPixBuf.gdk_pixbuf_new_from_stream(gdkStream, IntPtr.Zero, out IntPtr errorPtr);

            try
            {
                if (pixbuf == IntPtr.Zero)
                {
                    string gdkErrorMessage;
                    if (errorPtr != IntPtr.Zero)
                    {
                        GError error = Marshal.PtrToStructure <GError>(errorPtr);
                        gdkErrorMessage = error.message;
                    }
                    else
                    {
                        gdkErrorMessage = "Unknown error.";
                    }

                    throw new IOException($"{nameof(LibGdkPixBuf.gdk_pixbuf_new_from_stream)} error: {gdkErrorMessage}");
                }

                var source = GdkPixBufBitmapSource.Create(pixbuf);
                pixbuf = IntPtr.Zero;
                return(source);
            }
            finally
            {
                if (pixbuf != IntPtr.Zero)
                {
                    LibGdkPixBuf.g_object_unref(pixbuf);
                }

                if (errorPtr != IntPtr.Zero)
                {
                    LibGdkPixBuf.g_error_free(errorPtr);
                }
            }
        }