我现在把gif格式转换成png,其中有些颜色变透明了,谁知道大概是那一块出错了啊讲下原理也可以
解决方案 »
- 多种方法 获取 COOKIE 都不完整.............
- C#如何根据参数的不同,引用不同的类
- C#后台捕捉按键的问题。。
- 文件结构分析方法
- 怎么把读出来的数据绑定在zedGraphControl显示 用winform做的曲线图
- C# 垃圾回收
- An error occurred while parsing EntityName.请教高手解决
- [求教]请教ASP.NET中可以根据显示的字符长度自动换行的控件
- 我刚才申请了一个花生护照,同时有了一个免费域名(****.vicp.net),请问我可以让这个域名指到我的局域网的WEB服务器的IP(192.168.1.99)吗?
- Winform:如何使dataGrid不墨认选中第一条记录?
- 关于串口的几个属性的含义
- winform登录后开始加载主窗体并显示闪屏
格式转化很容易的,一行代码.private void button22_Click(object sender, EventArgs e)
{
Image.FromFile("d:\\temp.gif").Save("d:\\temp.png", System.Drawing.Imaging.ImageFormat.Png);
}
就想问这个
CxImage::pDib代表着背景图像,
CxImage::pAlpha代表着透明层,
CxImage:: pSelection代表着被选中的层,用来创建图像处理时的区域。
RGBQUAD nBkgndColor; // 这项用于设置背景透明度(RGB三原色透明度)
你的Image对象为8为色 保存出来就是Png8 24就是24
你保存到PNG图形为透明了。可能你的Image实例里的颜色ALPHA为透明了 根据Bitmap获取BitmapData 循环数据更改ALPAH的值. 如果是索引图只需要更改
Bitmap.Palette.Entries 就可以了...
///
/// </summary>
/// <param name="BackBmp">背景</param>
/// <param name="ForeBmp">前图</param>
/// <param name="ForeLeft">前景left</param>
/// <param name="ForeTop">top</param>
/// <param name="ForeBmpWidth">width</param>
/// <param name="ForeBmpHeight">height</param>
/// <param name="diaphaneityKey">透明度</param>
/// <param name="bkColor">设置自身透明度时用</param>
/// <param name="isSelf">是否设置自身</param>
/// <returns></returns>
private Bitmap SetDiaphaneity(Bitmap BackBmp, Bitmap ForeBmp, int ForeLeft, int ForeTop, int ForeBmpWidth, int ForeBmpHeight, float diaphaneityKey, bool isSelf)
{
float[][] nArray ={
new float[] {1, 0, 0, 0, 0},
new float[] {0, 1, 0, 0, 0},
new float[] {0, 0, 1, 0, 0},
new float[] {0, 0, 0, diaphaneityKey, 0},
new float[] {0, 0, 0, 0, 1}
};
ForeBmp.MakeTransparent(ForeBmp.GetPixel(0, 0));
ColorMatrix matrix = new ColorMatrix(nArray);
ImageAttributes attributes = new ImageAttributes();
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
Graphics g = Graphics.FromImage(BackBmp);
if (isSelf) g.Clear(System.Drawing.Color.White);
g.DrawImage(ForeBmp, new Rectangle(new Point(ForeLeft, ForeTop),new Size(ForeBmpWidth, ForeBmpHeight)), 0, 0, BackBmp.Width, BackBmp.Height, GraphicsUnit.Pixel, attributes);
g.Dispose();
return BackBmp;
}
这个应该对你有用吧。看下。