请问有没有办法把gif格式的图片转换成jpg格式
slyly 2006-06-26 04:50:09 学习打水印程序时,出现“无法从带有索引像素格式的图像创建 Graphics 对象”这样的错误!查到这样一篇文章(http://blog.csdn.net/johnsuna/articles/722412.aspx),但看不懂。哪位高手帮帮忙啊!就只有那个gif图片不行!代码如下:
===========================================
/// <summary>
/// 打水印
/// </summary>
/// <param name="img">图片</param>
/// <param name="newfileName">打水印后新图片的保存路径</param>
/// <param name="watermarkString">水印文字</param>
/// <param name="StrFormat">对齐方式</param>
public static void Seal(System.Drawing.Image img,string newfileName,string watermarkString,StringFormat StrFormat)
{
//Bitmap bmp = new Bitmap(img.Width,img.Height,PixelFormat.Format8bppIndexed);
Graphics g = Graphics.FromImage(img);
g.DrawImage(img,0,0,img.Width,img.Height);
int[] sizes = new int[]{16,14,12,10,8,6,4};
Font font = null;
SizeF crSize = new SizeF();
for (int i=0 ;i<7; i++)
{
font = new Font("Verdana", sizes[i],
FontStyle.Bold);
crSize = g.MeasureString(watermarkString,font);
if((ushort)crSize.Width < (ushort)img.Width)
break;
}
RectangleF stringRec1,stringRec2;
if(StrFormat.Alignment == StringAlignment.Center)
{
stringRec1 = new RectangleF(1,1,img.Width-1,img.Height-1);
stringRec2 = new RectangleF(1,1,img.Width-3,img.Height-1);
}
else if(StrFormat.Alignment == StringAlignment.Near)
{
stringRec1 = new RectangleF(1,1,img.Width,img.Height-1);
stringRec2 = new RectangleF(2,2,img.Width,img.Height-1);
}
else
{
stringRec1 = new RectangleF(1,1,img.Width-1,img.Height-1);
stringRec2 = new RectangleF(1,1,img.Width-2,img.Height-1);
}
//***********************
// 两个Brush做出阴影效果
//***********************
//黑色
SolidBrush semiTransBrush2 = new SolidBrush(Color.FromArgb(153, 0, 0, 0));
g.DrawString(watermarkString,font,semiTransBrush2,stringRec1,StrFormat);
//高亮
SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(153, 255, 255, 255));
g.DrawString(watermarkString,font,semiTransBrush,stringRec2,StrFormat);
//***********************
g.Dispose();
img.Save(newfileName);
img.Dispose();
}