示例#1
0
        public static void DrawBitmap(this ID2D1DeviceContext context,
                                      ID2D1Bitmap bitmap,
                                      float opacity = 1,
                                      D2D1_INTERPOLATION_MODE interpolationMode = D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR,
                                      D2D_RECT_F?destinationRectangle           = null,
                                      D2D_RECT_F?sourceRectangle            = null,
                                      D2D_MATRIX_4X4_F?perspectiveTransform = null)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

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

            using (var drc = destinationRectangle.StructureToMemory())
            {
                using (var src = sourceRectangle.StructureToMemory())
                {
                    if (perspectiveTransform.HasValue || (int)interpolationMode > (int)D2D1_BITMAP_INTERPOLATION_MODE.D2D1_BITMAP_INTERPOLATION_MODE_LINEAR)
                    {
                        using (var per = perspectiveTransform.StructureToMemory())
                        {
                            context.DrawBitmap(bitmap, drc.Pointer, opacity, interpolationMode, src.Pointer, per.Pointer);
                        }
                    }
                    else
                    {
                        context.DrawBitmap(bitmap, drc.Pointer, opacity, (D2D1_BITMAP_INTERPOLATION_MODE)interpolationMode, src.Pointer);
                    }
                }
            }
        }
        public static void DrawBitmap(this ID2D1DeviceContext device,
                                      ID2D1Bitmap bitmap,
                                      float opacity,
                                      D2D1_BITMAP_INTERPOLATION_MODE interpolationMode,
                                      D2D_RECT_F?destinationRectangle = null,
                                      D2D_RECT_F?sourceRectangle      = null)
        {
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            using (var drc = destinationRectangle.StructureToMemory())
            {
                using (var src = sourceRectangle.StructureToMemory())
                {
                    device.DrawBitmap(bitmap, drc.Pointer, opacity, interpolationMode, src.Pointer);
                }
            }
        }
        public static void DrawBitmap(this ID2D1DeviceContext device,
                                      ID2D1Bitmap bitmap,
                                      float opacity,
                                      D2D1_BITMAP_INTERPOLATION_MODE interpolationMode,
                                      D2D_RECT_F?destinationRectangle = null,
                                      D2D_RECT_F?sourceRectangle      = null)
        {
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            using (var drc = destinationRectangle.StructureToMemory())
            {
                using (var src = sourceRectangle.StructureToMemory())
                {
#pragma warning disable CA2010 // Always consume the value returned by methods marked with PreserveSigAttribute
                    device.DrawBitmap(bitmap, drc.Pointer, opacity, interpolationMode, src.Pointer);
#pragma warning restore CA2010 // Always consume the value returned by methods marked with PreserveSigAttribute
                }
            }
        }