Sun_china

交流更多,收获更多?

博客园 首页 新随笔 联系 订阅 管理

  //加图片水印
                    System.Drawing.Image image = System.Drawing.Image.FromFile(path + picName);
                    System.Drawing.Image watermakeImage = System.Drawing.Image.FromFile(CopyPicpath);
                    Graphics g = Graphics.FromImage(image);

                    int x = 0; //x坐标
                    int y = 0; //y坐标

                    switch (position)
                    {
                        case "0": //左上
                            x = 0;
                            y = 0;
                            break;
                        case "1": //右上
                            x = image.Width - watermakeImage .Width;
                            y = 0;
                            break;
                        case "2": //左下
                            x = 0;
                            y = image.Height - watermakeImage .Height;
                            break;
                        case "3": //右下
                            x = image.Width - watermakeImage .Width;
                            y = image.Height - watermakeImage .Height;
                            break;
                        default:
                            break;
                    }
                    g.DrawImage(watermakeImage , new Rectangle(x, y, watermakeImage .Width, watermakeImage .Height), 0, 0, watermakeImage .Width, watermakeImage .Height, GraphicsUnit.Pixel);
                    g.Dispose();

                    //保存加水印过后的图片,删除原始图片
                    string newPath = path + "New_" + picName; 

                    image.Save(newPath);
                    picNameWaterMack = "New_" + picName;
                    image.Dispose();
                    if (File.Exists(path + picName))
                    {
                        File.Delete(path + picName);
                    }

posted on 2008-04-28 11:07  Sun_china  阅读(463)  评论(0编辑  收藏  举报