日期:2014-05-18  浏览次数:21062 次

C#中DrawImage(emf矢量图),如何背景透明?
我用Adobe Illustrator做了一副矢量图,保存为emf格式.
在VS.NET 2003 中新建一个UserControl,在重写OnPaint方法如下:
MetaFile metaFile = new MetaFile("C:\1.emf");
e.Graphics.DrawImage(metaFile,e.ClipRectangle);
这样描绘出来的图象背景是不透明的
用了SetStyle(ControlStyles.SupportTransparent,true)后将控件BackColor = Color.Transparent也无效
设定Form的TransparencyKey为控件的背景色,也无效.
转换成Bitmap后MakeTransparent(bitMap.GetPixel(1,1))还是无效......
emf文件本身是背景透明的,不用转换成什么gif格式,因为转换了就不是矢量图了.
但是在控件上画出来就成了背景不透明了,谁能帮我啊?

------解决方案--------------------
不好意思,对GDI+不了解
------解决方案--------------------

用PictureBox呢?

------解决方案--------------------
关注
------解决方案--------------------
测试后是透明的,不过我的是VS2005,楼主升级个看看吧
C# code
private void button1_Click(object sender, EventArgs e)
{
    Metafile vMetafile = new Metafile(@"c:\temp\temp.emf");
    Graphics vGraphics = pictureBox1.CreateGraphics();
    vGraphics.DrawImage(vMetafile, 0, 0, 100, 100);
    vGraphics.Dispose();
}