C# winform 处理图片的特效用进度条来显示完成进度,请教高手

xywu_lili xywu_lili 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TuPianJinDuTiao
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
pictureBox1.ImageLocation = @"C:\Documents and Settings\Administrator\桌面\mnn.jpg";
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
}

public class ImageClass
{
/// <summary>马赛克效果</summary>
/// <param name="bmp">Bitmap 对象</param>
/// <param name="picBox">PictureBox 对象</param>
public static void MaSaiKe(Bitmap MyBitmap, PictureBox picBox)
{ //以马赛克效果显示图像
try
{
int dw = MyBitmap.Width / 50;
int dh = MyBitmap.Height / 50;
Graphics g = picBox.CreateGraphics();
g.Clear(Color.Gray);
Point[] MyPoint = new Point[2500];
for (int x = 0; x < 50; x++)
for (int y = 0; y < 50; y++)
{
MyPoint[x * 50 + y].X = x * dw;
MyPoint[x * 50 + y].Y = y * dh;
}
Bitmap bitmap = new Bitmap(MyBitmap.Width, MyBitmap.Height);
for (int i = 0; i < 10000; i++)
{
System.Random MyRandom = new Random();
int iPos = MyRandom.Next(2500);
for (int m = 0; m < dw; m++)
for (int n = 0; n < dh; n++)
{
bitmap.SetPixel(MyPoint[iPos].X + m, MyPoint[iPos].Y + n, MyBitmap.GetPixel(MyPoint[iPos].X + m, MyPoint[iPos].Y + n));
}
picBox.Refresh();
picBox.Image = bitmap;
}
for (int i = 0; i < 2500; i++)
for (int m = 0; m < dw; m++)
for (int n = 0; n < dh; n++)
{
bitmap.SetPixel(MyPoint[i].X + m, MyPoint[i].Y + n, MyBitmap.GetPixel(MyPoint[i].X + m, MyPoint[i].Y + n));
}
picBox.Refresh();
picBox.Image = bitmap;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "信息提示");
}
}
}

private void btnMaSaiKe_Click(object sender, EventArgs e)
{
ImageClass.MaSaiKe(new System.Drawing.Bitmap(this.pictureBox1.Image), pictureBox1);
}

}
}
该程序实现了把一张图片加入马赛克的特效。现在的问题是,图片的马赛克效果处理过程有点慢,如何加入一个进度条来显示图像的完成进度?要求有具体的实现代码。
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
xywu_lili
C# 111,128 成员 642,536 内容