[英]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.