public void CopyToImage(X11Image image) { if (image.Height != height || image.Width != width) { throw new InvalidOperationException($"Source size ({width} x {height}) does not match image size ({image.Width} x {image.Height})."); } using (X11Bitmap xBitmap = X11Bitmap.Create(image.Display, image.Visual, width, height)) { if (pixelFormat == PixelFormat.RGBA_32) { PixelConverter.Convert_RGBA_32BE_To_PARGB_32(dataPtr, stride, xBitmap.ImageData, 4 * width, width, height); } else if (pixelFormat == PixelFormat.RGB_24) { PixelConverter.Convert_RGB_24BE_To_ARGB_32(dataPtr, stride, xBitmap.ImageData, 4 * width, width, height); } else { throw new InvalidOperationException($"Unexpected pixel format: {pixelFormat}."); } var gcValues = new XGCValues(); var gc = LibX11.XCreateGC(image.Display, image.PixmapId, 0, ref gcValues); try { LibX11.XPutImage(image.Display, image.PixmapId, gc, xBitmap.XImage, 0, 0, 0, 0, (uint)width, (uint)height); } finally { LibX11.XFreeGC(image.Display, gc); } } }