6
6
using Windows . Support ;
7
7
using Windows . Win32 . Graphics . Direct2D . Common ;
8
8
using Windows . Win32 . Graphics . DirectWrite ;
9
+ using Windows . Win32 . Graphics . Imaging ;
9
10
10
11
namespace Windows . Win32 . Graphics . Direct2D ;
11
12
@@ -115,4 +116,54 @@ public static void DrawTextLayout<TTarget, TLayout, TBrush>(
115
116
GC . KeepAlive ( textLayout ) ;
116
117
GC . KeepAlive ( defaultFillBrush ) ;
117
118
}
119
+
120
+ /// <inheritdoc cref="ID2D1RenderTarget.CreateBitmapFromWicBitmap(IWICBitmapSource*, D2D1_BITMAP_PROPERTIES*, ID2D1Bitmap**)"/>
121
+ public static Bitmap CreateBitmapFromWicBitmap < TRenderTarget , TBitmapSource > (
122
+ this TRenderTarget target ,
123
+ TBitmapSource wicBitmap )
124
+ where TRenderTarget : IPointer < ID2D1RenderTarget >
125
+ where TBitmapSource : IPointer < IWICBitmapSource >
126
+ {
127
+ ID2D1Bitmap * d2dBitmap ;
128
+ target . Pointer ->CreateBitmapFromWicBitmap (
129
+ wicBitmap . Pointer ,
130
+ bitmapProperties : ( D2D1_BITMAP_PROPERTIES * ) null ,
131
+ & d2dBitmap ) . ThrowOnFailure ( ) ;
132
+
133
+ Bitmap bitmap = new ( d2dBitmap ) ;
134
+ GC . KeepAlive ( target ) ;
135
+ GC . KeepAlive ( wicBitmap ) ;
136
+ return bitmap ;
137
+ }
138
+
139
+ public static void DrawBitmap < TRenderTarget , TBitmap > (
140
+ this TRenderTarget target ,
141
+ TBitmap bitmap ,
142
+ RectangleF destinationRectangle = default ,
143
+ float opacity = 1.0f ,
144
+ BitmapInterpolationMode interpolationMode = BitmapInterpolationMode . Linear )
145
+ where TRenderTarget : IPointer < ID2D1RenderTarget >
146
+ where TBitmap : IPointer < ID2D1Bitmap >
147
+ {
148
+ D2D_RECT_F destination = ( D2D_RECT_F ) destinationRectangle ;
149
+ if ( destinationRectangle . IsEmpty )
150
+ {
151
+ D2D_SIZE_F size = target . Pointer ->GetSizeHack ( ) ;
152
+ destination = new D2D_RECT_F { left = 0 , top = 0 , right = size . width , bottom = size . height } ;
153
+ }
154
+ else
155
+ {
156
+ destination = ( D2D_RECT_F ) destinationRectangle ;
157
+ }
158
+
159
+ target . Pointer ->DrawBitmap (
160
+ bitmap . Pointer ,
161
+ & destination ,
162
+ opacity ,
163
+ ( D2D1_BITMAP_INTERPOLATION_MODE ) interpolationMode ,
164
+ null ) ;
165
+
166
+ GC . KeepAlive ( target ) ;
167
+ GC . KeepAlive ( bitmap ) ;
168
+ }
118
169
}
0 commit comments