@@ -46,46 +46,15 @@ static unsafe HRESULT IOleServices.GetDataHere(string format, object data, FORMA
46
46
{
47
47
if ( format . Equals ( DataFormatNames . Bitmap ) && data is Bitmap bitmap )
48
48
{
49
- // Save bitmap
50
- pmedium ->u . hBitmap = GetCompatibleBitmap ( bitmap ) ;
49
+ // GDI+ returns a DIBSECTION based HBITMAP. The clipboard only deals well with bitmaps created using
50
+ // CreateCompatibleBitmap(). So, we convert the DIBSECTION into a compatible bitmap.
51
+ pmedium ->u . hBitmap = bitmap . GetHBITMAP ( ) . CreateCompatibleBitmap ( bitmap . Width , bitmap . Height ) ;
51
52
}
52
53
53
54
return HRESULT . S_OK ;
54
55
}
55
56
56
57
return HRESULT . DV_E_TYMED ;
57
-
58
- static HBITMAP GetCompatibleBitmap ( Bitmap bitmap )
59
- {
60
- using var screenDC = GetDcScope . ScreenDC ;
61
-
62
- // GDI+ returns a DIBSECTION based HBITMAP. The clipboard only deals well with bitmaps created using
63
- // CreateCompatibleBitmap(). So, we convert the DIBSECTION into a compatible bitmap.
64
- HBITMAP hbitmap = bitmap . GetHBITMAP ( ) ;
65
-
66
- // Create a compatible DC to render the source bitmap.
67
- using CreateDcScope sourceDC = new ( screenDC ) ;
68
- using SelectObjectScope sourceBitmapSelection = new ( sourceDC , hbitmap ) ;
69
-
70
- // Create a compatible DC and a new compatible bitmap.
71
- using CreateDcScope destinationDC = new ( screenDC ) ;
72
- HBITMAP compatibleBitmap = PInvokeCore . CreateCompatibleBitmap ( screenDC , bitmap . Size . Width , bitmap . Size . Height ) ;
73
-
74
- // Select the new bitmap into a compatible DC and render the blt the original bitmap.
75
- using SelectObjectScope destinationBitmapSelection = new ( destinationDC , compatibleBitmap ) ;
76
- PInvokeCore . BitBlt (
77
- destinationDC ,
78
- 0 ,
79
- 0 ,
80
- bitmap . Size . Width ,
81
- bitmap . Size . Height ,
82
- sourceDC ,
83
- 0 ,
84
- 0 ,
85
- ROP_CODE . SRCCOPY ) ;
86
-
87
- return compatibleBitmap ;
88
- }
89
58
}
90
59
91
60
static unsafe bool IOleServices . TryGetBitmapFromDataObject < T > ( Com . IDataObject * dataObject , [ NotNullWhen ( true ) ] out T data )
0 commit comments