http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 23342|回复: 5

[asp.net] C#去除图片水印之马赛克解决方案(右下角去除方法)

[复制链接]
发表于 2014-12-13 10:10:09 | 显示全部楼层 |阅读模式
C#去除图片水印之马赛克解决方案(右下角去除方法)

看下效果
QQ截图20141213101125.jpg

处理效果如上图片,怎么样还可以吧,
大家可以根据自己的情况调整级别就行了。
代码实现如下
[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;

namespace AutoImage
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string path = string.Empty;
        //选择图片
        private void button1_Click(object sender, EventArgs e)
        {
            //选择文件
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Multiselect = true;
            //文件格式
            openFileDialog.Filter = "所有文件|*.*";
            //还原当前目录
            openFileDialog.RestoreDirectory = true;
            //默认的文件格式
            openFileDialog.FilterIndex = 1;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                path = openFileDialog.FileName;
                pictureBox1.BackgroundImage = Image.FromFile(path);
            }
        }
        //窗体加载事件
        private void Form1_Load(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 马赛克处理
        /// </summary>
        /// <param name="bitmap">要处理的图片</param>
        /// <param name="effectWidth"> 影响范围 每一个格子数 </param>
        /// <returns></returns>
        public System.Drawing.Bitmap AdjustTobMosaic(System.Drawing.Bitmap bitmap, int effectWidth)
        {
            // 差异最多的就是以照一定范围取样 玩之后直接去下一个范围
            for (int heightOfffset = bitmap.Height - bitmap.Height / 3; heightOfffset < bitmap.Height; heightOfffset += effectWidth)
            {
                for (int widthOffset = bitmap.Width -Convert.ToInt32( bitmap.Width*0.7); widthOffset < bitmap.Width; widthOffset += effectWidth)
                {
                    int avgR = 0, avgG = 0, avgB = 0;
                    int blurPixelCount = 0;

                    for (int x = widthOffset; (x < widthOffset + effectWidth && x < bitmap.Width); x++)
                    {
                        for (int y = heightOfffset; (y < heightOfffset + effectWidth && y < bitmap.Height); y++)
                        {
                            System.Drawing.Color pixel = bitmap.GetPixel(x, y);
                            //三元颜色平均值
                            avgR += pixel.R;
                            avgG += pixel.G;
                            avgB += pixel.B;
                            //统计
                            blurPixelCount++;
                        }
                    }

                    // 计算范围平均
                    avgR = avgR / blurPixelCount;
                    avgG = avgG / blurPixelCount;
                    avgB = avgB / blurPixelCount;

                    // 所有范围内都设定此值
                    for (int x = widthOffset; (x < widthOffset + effectWidth && x < bitmap.Width); x++)
                    {
                        for (int y = heightOfffset; (y < heightOfffset + effectWidth && y < bitmap.Height); y++)
                        {
                            System.Drawing.Color newColor = System.Drawing.Color.FromArgb(avgR, avgG, avgB);
                            bitmap.SetPixel(x, y, newColor);
                        }
                    }
                }
            }

            return bitmap;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Bitmap newimag = new Bitmap(path);
            pictureBox2.BackgroundImage = AdjustTobMosaic(newimag, Convert.ToInt32(textBox1.Text.Trim()));
        }

    }

    public enum WaterPositionMode
    {
        LeftTop,
        LeftBottom,
        RightTop,
        RightBottom,
        Center
    }
}

源码下载
图片马赛克处理.zip (12.44 KB, 下载次数: 77)

本帖被以下淘专辑推荐:



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2014-12-13 11:20:19 | 显示全部楼层
强烈支持楼主ing……
发表于 2014-12-13 23:24:25 | 显示全部楼层
受教了学习中……
发表于 2015-3-6 14:11:00 | 显示全部楼层
受教了学习中……
发表于 2015-3-24 00:38:34 | 显示全部楼层
留个脚印表示我来过!
发表于 2019-8-22 14:47:21 | 显示全部楼层
强烈支持楼主ing…
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-3-29 09:20

© 2014-2021

快速回复 返回顶部 返回列表