[英]How would you add an image (watermark) while capturing a video [directshow.net]?
我一直在使用DirectShowNET示例中的DxLogo項目。 這會將圖像添加到視頻中,但是在移動時會扭曲圖像的顏色,並且也無法處理透明背景。 因此,為了使其能夠處理這些因素...
我需要將幀轉換為位圖的一些方法:
Bitmap v = new Bitmap(m_videoWidth, m_videoHeight, m_stride, PixelFormat.Format32bppArgb, pBuffer);
然后將水印添加到新的位圖:
Graphics g = Graphics.FromImage(v);
g.DrawImage(m_Bitmap, 0, 0, m_Bitmap.Width, m_Bitmap.Height);
v = new Bitmap(v.Width, v.Height, g);
然后讓BufferCB將新的位圖作為幀,這就是我要堅持的地方。 你會怎么做?
原始DxLogo BufferCB方法:
int ISampleGrabberCB.BufferCB( double SampleTime, IntPtr pBuffer, int BufferLen )
{
// Avoid the possibility that someone is calling SetLogo() at this instant
lock (this)
{
if (m_bmdLogo != null)
{
for (int x = 0; x < m_bmdLogo.Height; x++)
{
CopyMemory(ipDest, ipSource, (uint)m_bmdLogo.Stride);
ipSource = (IntPtr)(ipSource.ToInt32() + m_bmdLogo.Stride);
ipDest = (IntPtr)(ipDest.ToInt32() + m_stride);
}
}
}
return 0;
}
謝謝!
發現問題,以防其他人遇到問題。 從pBuffer
創建位墊時,我使用了錯誤的PixelFormat
。 代替PixelFormat.Format32bppArgb
使用PixelFormat.Format24bppRgb
。
這是DxLogo示例的工作BufferCB:
int ISampleGrabberCB.BufferCB( double SampleTime, IntPtr pBuffer, int BufferLen )
{
// Avoid the possibility that someone is calling SetLogo() at this instant
lock (this)
{
if (m_Bitmap != null)
{
Bitmap v;
v = new Bitmap(m_videoWidth, m_videoHeight, m_stride, PixelFormat.Format24bppRgb, pBuffer);
Graphics g = Graphics.FromImage(v);
g.DrawImage(m_Bitmap, 100, 100, m_Bitmap.Width, m_Bitmap.Height);
}
}
這解決了以下問題:如果重新定位並且透明背景現在起作用,則圖像顏色會失真。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.