当前位置:编程学习 > C#/ASP.NET >>

视频叠加

请问有谁会用.net实现视频叠加?

就是在视频上添加文字等 --------------------编程问答-------------------- 冒泡帮顶接分 --------------------编程问答-------------------- 你可以做一个自定义控件, 把控件的形状挖成文字的形状. 这样就作到了真正的透明.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace TransparenceFont
{
    public partial class RealTransparentLabel : UserControl
    {
        private string text;

        public string _Text
        {
            get { return text; }
            set
            {
                text = value;
                OnTextChanged();
            }
        }

        public RealTransparentLabel()
        {
            InitializeComponent();
            this._Text = this.Name;
        }

        private void OnTextChanged()
        {
            if (text == null || text == "")
            {
                this.Width = 1;
                return;
            }
            //计算文字区域大小
            Bitmap tmp = new Bitmap(1, 1);
            Graphics measure = Graphics.FromImage(tmp);
            SizeF sz = measure.MeasureString(text, Font);
            tmp.Dispose();
            measure.Dispose();
            Size size = new Size((int)sz.Width, (int)sz.Height);
            this.Size = size;

            //绘制文字
            Bitmap img = new Bitmap(size.Width, size.Height);
            Graphics gph = Graphics.FromImage(img);
            gph.DrawString(text, Font, new SolidBrush(ForeColor), 0, 0);
            gph.Dispose();
            this.BackgroundImage = img;

            //除去控件多余区域
            Color transp = img.GetPixel(0,0);
            Region reg = new Region();
            reg.MakeEmpty();
            for (int i = 0; i < size.Width; i++)
            {
                for (int j = 0; j < size.Height; j++)
                {
                    if (img.GetPixel(i, j) != transp)
                    {
                        reg.Union(new Rectangle(i, j, 1, 1));
                    }
                }
            }
            this.Region = reg;
        }
    }
}


效果如图下面的对比是普通Label控件用透明色做背景, 其背景只是窗体的背景.
而RealTransparentLabel完全透明了.
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,