Visual Basic.NET 7.x (2002/03)DirectXVisual Basic 9 (2008)Visual Basic 8 (2005).NET 1.0.NET 1.1.NET 3.0.NET 2.0.NET 3.5中级开发.NETVisual Basic
DirectShow.Net 的 ProcAmp






1.92/5 (6投票s)
如何在 DirectShow.Net 滤镜图中运用亮度、对比度、饱和度和色调。
引言
我正在撰写一系列文章,将详细介绍 DirectShow.Net 的使用方法。当有足够的示例时,我将把它们组合成一个用 VB.NET 编写的完整视频播放器程序。
本文将解释如何扩展你的滤镜图以使用 ProcAmp 控制。ProcAmp 真是个很酷的东西!让我们把你的电影变成彩虹般的颜色吧!我使用的是 DirectShow.Net 库。它让你可以在 VB.NET/C# 中构建 DirectShow 组件。请注意,并非所有滤镜图都支持此技巧。if then
代码部分尝试捕获这一点。
使用代码
请先创建一个滤镜图。我这里只给出了亮度的一个示例,但通过添加一些额外的代码行,色调、对比度和饱和度也可以以相同的方式工作。
这段代码放在你的 .renderstream
函数之后。f_VideoMixing_Renderer
是一个 VideoMixingRenderer9
对象(这是我的滤镜图的一部分)。
f_VideoMixerProcampControl
是一个控件(VMR9ProcAmpControl
),它让你能够访问视频的色彩调整功能。
f_VideoMixerProcampRange
(VMR9ProcAmpControlRange
)是你要放入并从 ProcAmp 控制中取出的对象。在获取或设置 ProcAmp 中的内容时,你总是需要使用 marshal.sizeof
。
'********************************** video procamp *****************************************
'new setup mixer control
Dim f_VideoMixerControl As IVMRMixerControl9 = _
CType(f_VideoMixingRenderer, IVMRMixerControl9)
DsError.ThrowExceptionForHR(hr)
'new setup procamp control
Dim f_VideoMixerProcampControl As VMR9ProcAmpControl
f_VideoMixerProcampControl.dwSize = Marshal.SizeOf(f_VideoMixerProcampControl)
f_VideoMixerProcampControl.dwFlags = 0
hr = f_VideoMixerControl.GetProcAmpControl(0, f_VideoMixerProcampControl)
DsError.ThrowExceptionForHR(hr)
If (f_VideoMixerProcampControl.dwFlags And VMR9ProcAmpControlFlags.Brightness) > 0 Then
Debug.WriteLine("brightness")
End If
If (f_VideoMixerProcampControl.dwFlags And VMR9ProcAmpControlFlags.Contrast) > 0 Then
Debug.WriteLine("constrast")
End If
If (f_VideoMixerProcampControl.dwFlags And VMR9ProcAmpControlFlags.Hue) > 0 Then
Debug.WriteLine("hue")
End If
If (f_VideoMixerProcampControl.dwFlags And VMR9ProcAmpControlFlags.Mask) > 0 Then
Debug.WriteLine("mask")
End If
If (f_VideoMixerProcampControl.dwFlags And VMR9ProcAmpControlFlags.None) > 0 Then
Debug.WriteLine("none")
End If
If (f_VideoMixerProcampControl.dwFlags And VMR9ProcAmpControlFlags.Saturation) > 0 Then
Debug.WriteLine("saturation")
End If
'get procamp control range for brightness
Dim f_VideoMixerProcampRange As VMR9ProcAmpControlRange
f_VideoMixerProcampRange.dwProperty = VMR9ProcAmpControlFlags.Brightness
f_VideoMixerProcampRange.dwSize = Marshal.SizeOf(f_VideoMixerProcampRange)
hr = f_VideoMixerControl.GetProcAmpControlRange(0,f_VideoMixerProcampRange)
DsError.ThrowExceptionForHR(hr)
'set the brightness in ProcAmp , tell that the size has changed
Dim brightpos As Double = 0.1
f_VideoMixerProcampControl.Brightness = _
CSng(f_VideoMixerProcampRange.MinValue + brightpos * _
(f_VideoMixerProcampRange.MaxValue - f_VideoMixerProcampRange.MinValue))
'set the new value in ProcAmp to the videomixercontrol
f_VideoMixerProcampControl.dwSize = Marshal.SizeOf(f_VideoMixerProcampControl)
hr = f_VideoMixerControl.SetProcAmpControl(0, f_VideoMixerProcampControl)
DsError.ThrowExceptionForHR(hr)
关注点
我花了两年时间学习 VB.NET,半年时间学习 DirectShow,以及半天时间来完成 ProcAmp。如果你是新手,你需要阅读我使用的每个命令的相关资料。
历史
这是这段代码的第一个版本..