-1
我想這款C++翻譯從this MSDN參考代碼,C#或VB.NET:如何定義'CreateDIB'函數或在C#中重現其目的?
case WM_DWMSENDICONICTHUMBNAIL:
{
// This window is being asked to provide its iconic bitmap. This indicates
// a thumbnail is being drawn.
hbm = CreateDIB(HIWORD(lParam), LOWORD(lParam));
if (hbm)
{
hr = DwmSetIconicThumbnail(hwnd, hbm, 0);
DeleteObject(hbm);
}
}
break;
乍一看似乎很簡單,但我需要幫助瞭解有關3210功能,我不知道該功能的用途和目的,我無法找到有關信息,也無法在Windows SDK頭文件中找到它,什麼也沒有。
在哪裏定義函數?,需要遵循該C++示例中的良好實踐?,如何從C#聲明它,或者哪個.NET是該非託管函數的等價物?
我發現CImageAllocator.CreateDIB這我不知道它是否reffers到,但函數的參數並不對應於一種CreateDIB(width, height)
就像我在this其他MSDN代碼所示,所以probablly是不一樣的功能,也是一個directshow的事情...
嗯,這是目前的翻譯我做了,它的工作原理,但我擔心可能的內存問題,因爲缺少3210函數或其等價物託管會員:
Case WM_DWMSENDICONICTHUMBNAIL
Dim hwnd As IntPtr = Process.GetCurrentProcess().MainWindowHandle
Dim dWord As Integer = m.LParam.ToInt32()
Dim maxWidth As Short = BitConverter.ToInt16(BitConverter.GetBytes(dWord), 2)
Dim maxHeight As Short = BitConverter.ToInt16(BitConverter.GetBytes(dWord), 0)
Using img As Image = Bitmap.FromFile("C:\Image.jpg")
Using thumb As Bitmap = CType(img.GetThumbnailImage(maxWidth, maxHeight, Nothing, Nothing), Bitmap)
Dim hBitmap As IntPtr = thumb.GetHbitmap()
Dim hresult As Integer = NativeMethods.DwmSetIconicThumbnail(hwnd, hBitmap, 0)
If (hresult <> 0) Then
' Handle error...
' Throw Marshal.GetExceptionForHR(hresult)
End If
NativeMethods.DeleteObject(hBitmap)
End Using
End Using
'CreateDIB'不是Win32函數;我的猜測是這是一個函數,它調用'CreateDIBSection',然後將縮略圖渲染到位圖中。 –
您鏈接到的MSDN文章表示這是來自較大示例項目的片段。但是我無法下載完整的項目,它似乎不再可用。所以我猜CreateDIB只是他們在這個示例中寫的一個函數。 – Saeed
https://github.com/pauldotknopf/WindowsSDK7-Samples/blob/e8fe83b043727e71f5179da11fc6228475e7973c/multimedia/directshow/baseclasses/winutil.cpp#L1632? – andlabs