示例#1
0
            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);
                    }
                }
            }
示例#2
0
        public void CopyFromBitmap(Rectangle imageArea, IntPtr bitmap, int bitmapStride)
        {
            // todo: create separate validation ?
            NativeBitmapSourceParameterValidation.CopyToBitmap(this, imageArea, bitmap, bitmapStride, out _);

            using (X11Bitmap xBitmap = X11Bitmap.Create(Display, Visual, imageArea.Width, imageArea.Height))
            {
                PixelConverter.Convert_ARGB_32_To_PARGB_32(bitmap, bitmapStride, xBitmap.ImageData, imageArea.Width * 4, imageArea.Width, imageArea.Height);

                var gcValues = new XGCValues();
                var gc       = LibX11.XCreateGC(Display, PixmapId, 0, ref gcValues);
                try
                {
                    LibX11.XPutImage(Display, PixmapId, gc, xBitmap.XImage, 0, 0, imageArea.X, imageArea.Y, (uint)imageArea.Width, (uint)imageArea.Height);
                }
                finally
                {
                    LibX11.XFreeGC(Display, gc);
                }
            }
        }