Example #1
0
        public static void DrawImage(this ID2D1DeviceContext context,
                                     ID2D1Effect effect,
                                     D2D1_INTERPOLATION_MODE interpolationMode = D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_LINEAR,
                                     D2D1_COMPOSITE_MODE compositeMode         = D2D1_COMPOSITE_MODE.D2D1_COMPOSITE_MODE_SOURCE_OVER,
                                     D2D_POINT_2F?targetOffset = null,
                                     D2D_RECT_F?imageRectangle = null)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (effect == null)
            {
                throw new ArgumentNullException(nameof(effect));
            }

            using (var irc = imageRectangle.StructureToMemory())
            {
                using (var to = targetOffset.StructureToMemory())
                {
                    effect.GetOutput(out var image);
                    try
                    {
                        context.DrawImage(image, to.Pointer, irc.Pointer, interpolationMode, compositeMode);
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(image);
                    }
                }
            }
        }
Example #2
0
        public static void DrawImage(this ID2D1DeviceContext context,
                                     ID2D1Image image,
                                     D2D1_INTERPOLATION_MODE interpolationMode = D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_LINEAR,
                                     D2D1_COMPOSITE_MODE compositeMode         = D2D1_COMPOSITE_MODE.D2D1_COMPOSITE_MODE_SOURCE_OVER,
                                     D2D_POINT_2F?targetOffset = null,
                                     D2D_RECT_F?imageRectangle = null)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }

            using (var irc = imageRectangle.StructureToMemory())
            {
                using (var to = targetOffset.StructureToMemory())
                {
                    context.DrawImage(image, to.Pointer, irc.Pointer, interpolationMode, compositeMode);
                }
            }
        }