zoukankan      html  css  js  c++  java
  • 上传图片 水印位置计算 记录一下

      //加图片水印
                        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);
                        }

  • 相关阅读:
    python 0.1
    写博
    ubuntu 下tomcat配置
    ubuntu Ulipad 配置
    git windows中文乱码 以及关键字加亮
    ubuntu windows mysql 中文乱码解决
    struts2 tomcat下生成文件保存指定的目录
    [你必须知道的.NET] 第二回:对抽象编程:接口和抽象类
    [你必须知道的.NET] 第三回:历史纠葛:特性和属性
    [你必须知道的.NET] 第一回:恩怨情仇:is和as
  • 原文地址:https://www.cnblogs.com/suneryong/p/1174213.html
Copyright © 2011-2022 走看看