无法从带有索引像素格式的图像创建 Graphics 对象

先转位图,将原图像画到位图上,再保存位图
protected void AddWater(string originalImage, string waterTextPictureName)
    {
        string addText = "gogolike.com";
        System.Drawing.Image image = System.Drawing.Image.FromFile(originalImage);

        System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(image.Width, image.Height);

        System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);

        g.DrawImage(image, 0, 0, image.Width, image.Height);
        System.Drawing.Font f = new System.Drawing.Font("Verdana", 60);
       
        System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Green);

       

        try
        {
            g.DrawString(addText, f, b, 35, 35);
         
            bitmap.Save(waterTextPictureName);
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;
            throw ex;
        }
        finally
        {

            f.Dispose();
            b.Dispose();
            bitmap.Dispose();
            g.Dispose();
            image.Dispose();
        }
    }
posted on 2007-12-25 10:08  品茶  阅读(2188)  评论(1编辑  收藏  举报