如何用GDI+实现透明的PNG格式图片文件的制作输出?

chx007 2003-01-16 10:15:26
如题!
...全文
184 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
Muf 2003-01-20
  • 打赏
  • 举报
回复
在IE中可能有透明色的概念(而不是Alpha=0的点)。
这种透明特色,只有256色模式才支持(PNG在这一点兼容GIF的这一特性)。
可能下一版本的IE可以使用带Alpha的图片吧。
chx007 2003-01-17
  • 打赏
  • 举报
回复
to:Muf(沐枫)
我是要用在IE上的!我刚才用FIREWORKS MX分别制作了PNG-8,PNG-24,PNG-32三种格式的透明图片文件,好像只有PNG-8在IE上能支持透明!!但颜色只有256色!!
Muf 2003-01-17
  • 打赏
  • 举报
回复
你如何看出不透明?
如果你有普通的看图软件,当然是灰底的了。
但如果你用PhotoShop,或者是使用你自已的程序在有色背景上画出来,就是透明的。
TheAres 2003-01-17
  • 打赏
  • 举报
回复
To chx007(乱发吹风):

Do you look on the 2nd article?
Could you post your code here?
chx007 2003-01-17
  • 打赏
  • 举报
回复
to:TheAres(班门斧)
我的代跟那些相似,都能输出PNG文件,但不能透明!
chx007 2003-01-17
  • 打赏
  • 举报
回复
我代码与http://www.dotnet247.com/247reference/msgs/26/133136.aspx上的想似!
using System;
using System.Drawing;
using System.Drawing.Imaging;
namespace ConsoleApplication1
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
public static void Main()
{
Bitmap newBitmap = null;
Graphics g = null ;
 
try
{
Font fontCounter = new Font("Lucida Sans Unicode", 12);
newBitmap = new Bitmap(97,26,PixelFormat.Format32bppArgb);
g = Graphics.FromImage(newBitmap);
g.Clear(Color.Transparent);//或者g.Clear(Color.FromArgb(0,Color.White));
g.DrawString("正正正", fontCounter,new SolidBrush(Color.FromArgb(127,255,0,0)), 0, 0);
 
newBitmap.Save("c:\\test.PNG", ImageFormat.Png);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
finally
{
if (null != g) g.Dispose();
if (null != newBitmap) newBitmap.Dispose();
}
}
}

}

输出的test.png在IE里的背景色的灰色的,可FIREWORKS MX或photoshop里是透明的!!
TheAres 2003-01-17
  • 打赏
  • 举报
回复
参考这个修改一下:

http://www.dotnet247.com/247reference/msgs/17/87941.aspx
http://www.dotnet247.com/247reference/msgs/26/133136.aspx
chx007 2003-01-16
  • 打赏
  • 举报
回复
Color.FromArgb(0,Color.White);和
Color.Transparent;
我试过,但一存成文件,就变成灰色的
feels30000 2003-01-16
  • 打赏
  • 举报
回复
模拟在FORM中画图:G是FORM的设备

g.clear(this.backcolor)
g.drawimg("你的GIF文件")
aspcn 2003-01-16
  • 打赏
  • 举报
回复
随便选一个颜色,然后将其设置为透明,然后再用他刷新背景。

Color myColor = Color.FromArgb(0,Color.White);
g.Clear(myColor);
chx007 2003-01-16
  • 打赏
  • 举报
回复
快来帮忙啊!

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧