zoukankan      html  css  js  c++  java
  • 发布文章自动上传图片并生成水印

    前段时间在网上看到新浪有一个提交文本(Html代码),自动上传图片的功能,觉得倒是很[实用,稍一琢磨,自己也写了这么一个东东。
    根据所传入的Html代码,获取标签中的图片标签,将图片复制到当前服务器,替换Html代码中图片标签的src属性值。如果需要,还可以打上水印,堂堂正正的说版权归本公司(个人)所有,哈!

    以下是主程序代码:

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Net;
    using System.Drawing;
    using System.Web;
    using System.IO;
    using System.Drawing.Imaging;

    namespace JL.SWSystem.SWCommon.Mrhgw
    {
        
    /// <summary>
        
    /// 根据传入的文本自动上传图片。
        
    /// </summary>

        public class ImageUploadAutomatic
        
    {

            
    静态构造器

            
    变量

            
    属性

            
    重置所有参数

            
    提交操作

            
    生成新的图片文件名称
        }

    }

    以下是参数类代码:

    using System;
    using System.Text;

    namespace JL.Automatic
    {
        
    /// <summary>
        
    /// 参数类。
        
    /// </summary>

        public class ParamItem
        
    {
            
    /// <summary>
            
    /// 默认构造器。
            
    /// </summary>

            public ParamItem()
            
    {

            }


            
    /// <summary>
            
    /// 构造器(重载二)。
            
    /// </summary>
            
    /// <param name="preImagePath">原图片地址</param>
            
    /// <param name="currentImagePath">当前图片链接地址</param>

            internal ParamItem(string preImagePath, string currentImagePath)
            
    {
                
    this.preImagePath = preImagePath;
                
    this.currentImagePath = currentImagePath;
            }


            
    /// <summary>
            
    /// 原图片地址。
            
    /// </summary>

            private string preImagePath = "";
            
    /// <summary>
            
    /// 当前图片链接地址。
            
    /// </summary>

            private string currentImagePath = "";

            
    /// <summary>
            
    /// 获取或设置原图片地址。
            
    /// </summary>

            public string PreImagePath
            
    {
                
    get return this.preImagePath; }
                
    set this.preImagePath = value; }
            }


            
    /// <summary>
            
    /// 获取或设置当前图片链接地址。
            
    /// </summary>

            public string CurrentImagePath
            
    {
                
    get return this.currentImagePath; }
                
    set this.currentImagePath = value; }
            }

        }

    }

    以下是生成水图的代码:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Drawing.Imaging;

    namespace JL.SWSystem.SWCommon.Mrhgw
    {
        
    /// <summary>
        
    /// 标记水印。
        
    /// </summary>

        public class ImageWatermark
        
    {
            
    标记文本水印

            
    标记图片水印
        }

    }


    以下是程序引用代码:

            string content = ""//Html标签。
            ImageUploadAutomatic.Text = content; //设置Html标签。
            ImageUploadAutomatic.FilePath = "../Images/Uploads"//设置图片上传路径。
            ImageUploadAutomatic.RefersImagePath= "/Images/Uploads"//设置图片引用路径。
            ImageUploadAutomatic.IsSignWatermark = true//确定生成水印。
            ImageUploadAutomatic.WatermarkImage = "../Images/Mark.png"//水印图片路径。
            ImageUploadAutomatic.Submit(); //提交生成。
            content = ImageUploadAutomatic.Text; //此处返回修改后的Html标签(仅修改了图片的链接地址)。
  • 相关阅读:
    URAL 1998 The old Padawan 二分
    URAL 1997 Those are not the droids you're looking for 二分图最大匹配
    URAL 1995 Illegal spices 贪心构造
    URAL 1993 This cheeseburger you don't need 模拟题
    URAL 1992 CVS
    URAL 1991 The battle near the swamp 水题
    Codeforces Beta Round #92 (Div. 1 Only) A. Prime Permutation 暴力
    Codeforces Beta Round #7 D. Palindrome Degree hash
    Codeforces Beta Round #7 C. Line Exgcd
    Codeforces Beta Round #7 B. Memory Manager 模拟题
  • 原文地址:https://www.cnblogs.com/mrhgw/p/531322.html
Copyright © 2011-2022 走看看