1- using D2Phap ;
1+ /*
2+ MIT License
3+ Copyright (C) 2022 DUONG DIEU PHAP
4+ Project & license info: https://github.com/d2phap/DXControl
5+ */
6+ using D2Phap ;
27using DirectN ;
38using WicNet ;
49
510namespace Demo ;
611
712public class DXCanvas : DXControl
813{
9- private ID2D1Bitmap ? _d2dBitmap = null ;
10-
14+ private IComObject < ID2D1Bitmap > ? _d2dBitmap = null ;
15+ private D2D_RECT_F rectText = new ( 100f , 100f , new ( 400 , 200 ) ) ;
16+
1117 public WicBitmapSource ? Image
1218 {
1319 set
1420 {
15- if ( DeviceContext == null || value == null )
21+ DXHelper . DisposeD2D1Bitmap ( ref _d2dBitmap ) ;
22+ GC . Collect ( ) ;
23+
24+ if ( Device == null || value == null )
1625 {
1726 _d2dBitmap = null ;
1827 return ;
@@ -31,9 +40,11 @@ public WicBitmapSource? Image
3140 } ;
3241 var bitmapPropsPtr = bitmapProps . StructureToPtr ( ) ;
3342
34- DeviceContext . CreateBitmapFromWicBitmap ( value . ComObject . Object , bitmapPropsPtr ,
35- out _d2dBitmap )
43+ Device . CreateBitmapFromWicBitmap ( value . ComObject . Object , bitmapPropsPtr ,
44+ out ID2D1Bitmap bmp )
3645 . ThrowOnError ( ) ;
46+
47+ _d2dBitmap = new ComObject < ID2D1Bitmap > ( bmp ) ;
3748 }
3849 }
3950
@@ -44,7 +55,7 @@ public DXCanvas()
4455 }
4556
4657
47- protected override void OnRender ( DXGraphics g )
58+ protected override void OnDirect2DRender ( DXGraphics g )
4859 {
4960 var p1 = new D2D_POINT_2F ( 0 , 0 ) ;
5061 var p2 = new D2D_POINT_2F ( ClientSize . Width , ClientSize . Height ) ;
@@ -57,8 +68,8 @@ protected override void OnRender(DXGraphics g)
5768 // draw image
5869 if ( _d2dBitmap != null )
5970 {
60- _d2dBitmap . GetSize ( out var size ) ;
61- g . DrawBitmap ( _d2dBitmap ,
71+ _d2dBitmap . Object . GetSize ( out var size ) ;
72+ g . DrawBitmap ( _d2dBitmap . Object ,
6273 new D2D_RECT_F ( 10f , 10f , size . width * 1 , size . height * 1 ) ,
6374 new D2D_RECT_F ( 0 , 0 , size . width , size . height ) ) ;
6475 }
@@ -95,17 +106,20 @@ protected override void OnRender(DXGraphics g)
95106
96107 }
97108
109+
98110
99- protected override void OnRender ( Graphics g )
111+ protected override void OnGdiPlusRender ( Graphics g )
100112 {
101113 using var pen = new Pen ( Color . Red , 5 ) ;
102114 g . DrawRectangle ( pen , new Rectangle (
103115 ( int ) rectText . left , ( int ) rectText . top - 50 ,
104116 ( int ) rectText . Width , ( int ) rectText . Height ) ) ;
117+
118+ g . DrawString ( $ "FPS: { FPS } - GDI+", Font , Brushes . Purple , new PointF ( 100 , 100 ) ) ;
105119 }
106120
107121
108- private D2D_RECT_F rectText = new ( 100f , 100f , new ( 400 , 200 ) ) ;
122+
109123 protected override void OnFrame ( FrameEventArgs e )
110124 {
111125 base . OnFrame ( e ) ;
0 commit comments