资源简介
【基于C#语言开发人脸皮肤图像分析软件】
【】
【
#region 截图方法
/// <summary>
/// 剪裁 -- 用GDI
/// </summary>
/// <param name="b">原始Bitmap</param>
/// <param name="StartX">开始坐标X</param>
/// <param name="StartY">开始坐标Y</param>
/// <param name="iWidth">宽度</param>
/// <param name="iHeight">高度</param>
/// <returns>剪裁后的Bitmap</returns>
public static Bitmap CutImage(Image b, int StartX, int StartY, int iWidth, int iHeight)
{
if (b == null)
{
return null;
}
int w = b.Width;
int h = b.Height;
Bitmap bmpOut = null;
try
{
bmpOut = new Bitmap(iWidth, iHeight);
Graphics g = Graphics.FromImage(bmpOut);
g.Clear(System.Drawing.Color.Transparent);
g.DrawImage(b, new Rectangle(0, 0, iWidth, iHeight), new Rectangle(StartX, StartY, iWidth, iHeight), GraphicsUnit.Pixel);
g.Dispose();
return bmpOut;
}
catch(Exception e)
{
MessageBox.Show(e.Message);
return null;
}
finally
{
b.Dispose();
// bmpOut.Dispose();
}
}
/// <summary>
/// 按照指定大小缩放图片,但是为了保证图片宽高比自动截取
/// </summary>
/// <param name="srcImage"></param>
/// <param name="iWidth"></param>
/// <param name="iHeight"></param>
/// <returns></returns>
public static Bitmap SizeImageWithOldPercent(Image ImageLocation1, int iWidth, int iHeight)
{
Bitmap cutedImage=null;
try
{
int newW = 1000;
int newH = 1000;
int newX = 0;
int newY = 0;
//取得符合比例的临时文件
cutedImage = CutImage(ImageLocation1, newX, newY, newW, newH);
// 保存到的文件
// Bitmap b = new Bitmap(iWidth, iHeight);
cutedImage.Save(path3, System.Drawing.Imaging.ImageFormat.Bmp);
return cutedImage;
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return null;
}
finally
{
ImageLocation1.Dispose();
cutedImage.Dispose();
}
}
#endregion
void UsingFileSystemWatcher()
{
FileSystemWatcher fswWatcher = new FileSystemWatcher();
fswWatcher.Path = path;
fswWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.LastAccess;
fswWatcher.Filter = "*.*";
fswWatcher.IncludeSubdirectories = true;
#region 实例化触发的事件(已定)
fswWatcher.Created = new FileSystemEventHandler(fswWatcher_Created);
fswWatcher.Changed = new FileSystemEventHandler(fswWatcher_Changed);
fswWatcher.Renamed = new RenamedEventHandler(fswWatcher_Renamed);
fswWatcher.Deleted = new FileSystemEventHandler(fswWatcher_Deleted);
#endregion
//获取或设置一个值,该值指示是否启用此组件。
fswWatcher.EnableRaisingEvents = true;
}//定义监控文件夹的方法
#region 监控图片传入
void fswWatcher_Created(object sender, FileSystemEventArgs e)
{
#region 修改图片名称并转存
System.Drawing.Image ImageLocation1=null;
try
{
string path2 = @"C:\copy2\" newName;
System.IO.File.Copy(e.FullPath, path2, true);
path3 = path2.Replace("copy2", "copy");
//Bitmap SizeImageWithOldPercent(Image ImageLocation1, int iWidth, int iHeight)
ImageLocation1 = System.Drawing.Image.FromFile(path2);
SizeImageWithOldPercent(ImageLocation1, ImageLocation1.Width, ImageLocation1.Height);//单独做成方法
}
catch
{
//
}
finally {
if (ImageLocation1 != null)
{
ImageLocation1.Dispose();
}
}
#endregion
}
#region 监控备用
private void ModifyFileName(string p, string p_2)
{
throw new NotImplementedException();
}
void fswWatcher_Changed(object sender, FileSystemEventArgs e)
{
}
void fswWatcher_Renamed(object sender, RenamedEventArgs e)
{
}
void fswWatcher_Deleted(object sender, FileSystemEventArgs e)
{
//DirectoryInfo dir = new DirectoryInfo(path);
//dir.Create();//自行判断一下是否存在。
}
#endregion
#endregion
private void Form1_Load(object sender, EventArgs e)
{
}
#region 皮肤算法集
private void 光泽度(object sender, EventArgs e)
{
try
{
test6.Class6 exp6 = new test6.Class6();
MWArray[] t = exp6.guangzedu(1);
MWNumericArray t1 = (MWNumericArray)t[0];
double[,] t2 = (double[,])t1.ToArray(MWArrayComponent.Real);
double t3 = t2[0, 0];
str6 = t3.ToString("N");
textBox6.Text = str6;
str6 = null;
}
catch (Exception)
{
// MessageBox.Show("图片错误,请重新选择!");
//Close();
}
finally
{
}
}
private void 粗糙度(object sender, EventArgs e)
{
try
{
test1.Class1 exp1 = new test1.Class1();
MWArray[] x = exp1.cucaodu(1);
MWNumericArray x1 = (MWNumericArray)x[0];
double[,] x2 = (double[,])x1.ToArray(MWArrayComponent.Real);
double x3 = x2[0, 0];
str1= x3.ToString("N");//将隐式int转换为string类型
textBox1.Text = str1;
str1 = null;
}
catch (Exception )
{
//MessageBox.Show("图片错误,请重新选择!");
// Close();
}
finally
{
MWArray.DisposeArray(e);
}
}
private void 纹理(object sender, EventArgs e)
{
try
{
test2.Class2 exp2 = new test2.Class2();
MWArray[] a = exp2.wenli(1);
MWNumericArray a1 = (MWNumericArray)a[0];
double[,] b2 = (double[,])a1.ToArray(MWArrayComponent.Real);
double b3 = b2[0, 0];
str2 = b3.ToString("N");
textBox2.Text = str2;
str2 = null;
}
catch (Exception )
{
// MessageBox.Show("图片错误,请重新选择!" );
// Close();
}
finally
{
MWArray.DisposeArray(e);
}
}
private void 色泽(object sender, EventArgs e)
{
try
{
test3.Class3 exp3 = new test3.Class3();
MWArray[] q = exp3.seze(1);
MWNumericArray q1 = (MWNumericArray)q[0];
double[,] q2 = (double[,])q1.ToArray(MWArrayComponent.Real);
double q3 = q2[0, 0];
str3 = q3.ToString("N");
textBox3.Text = str3;
str3 = null;
}
catch (Exception )
{
// MessageBox.Show("图片错误,请重新选择!" );
// Close();
}
finally
{
MWArray.DisposeArray(e);
}
}
private void 弹性(object sender, EventArgs e)
{
try
{
test4.Class4 exp4 = new test4.Class4();
MWArray[] w = exp4.tanxing(1);
MWNumericArray w1 = (MWNumericArray)w[0];
double[,] w2 = (double[,])w1.ToArray(MWArrayComponent.Real);
double w3 = w2[0, 0];
str4 = w3.ToString("N");
textBox4.Text = str4;
str4 = null;
}
catch (Exception )
{
// MessageBox.Show("图片错误,请重新选择!");
// Close();
}
finally
{
MWArray.DisposeArray(e);
}
}
private void 水份(object sender, EventArgs e)
{
try
{
test5.Class5 exp5 = new test5.Class5();
MWArray[] r = exp5.water(1);
MWNumericArray r1 = (MWNumericArray)r[0];
double[,] r2 = (double[,])r1.ToArray(MWArrayComponent.Real);
double r3 = r2[0, 0];
str5 = r3.ToString("N");
textBox5.Text = str5;
str5 = null;
}
catch (Exception )
{
//MessageBox.Show("图片错误,请重新选择!");
// Close();
}
finally
{
MWArray.DisposeArray(e);
}
}
#endregion
private void button2_Click_1(object sender, EventArgs e)
{
if (qq == 0)
{
Thread t = new Thread(DoWork);
t.Start();
粗糙度(sender, e);
纹理(sender, e);
色泽(sender, e);
光泽度(sender, e);
弹性(sender, e);
水份(sender, e);
str1 = null;
str2 = null;
str3 = null;
str4 = null;
str5 = null;
str6 = null;
string a = textBox6.Text.ToString();
ProgressBar1.ActiveForm.Close();
if (a == "100.00")
MessageBox.Show("光泽度有误,请重新上传!");
else if (a == "")
MessageBox.Show("结果不能为空,请重新选取图片");
else
MessageBox.Show("图片分析结果正确");
t.Abort();
qq ;
}
else
{
Thread l = new Thread(DoWork1);
l.Start();
textBox1.Text = first.ToString("G");
textBox2.Text = first.ToString("G");
textBox3.Text = first.ToString("G");
textBox4.Text = first.ToString("G");
textBox5.Text = first.ToString("G");
textBox6.Text = first.ToString("G");
粗糙度(sender, e);
纹理(sender, e);
色泽(sender, e);
光泽度(sender, e);
弹性(sender, e);
水份(sender, e);
str1 = null;
str2 = null;
str3 = null;
str4 = null;
str5 = null;
str6 = null;
string zz = textBox6.Text.ToString();
ProgressBar2.ActiveForm.Close();
if (zz == "100.00")
MessageBox.Show("光泽度有误,请重新上传!");
else if (zz == "")
MessageBox.Show("结果不能为空,请重新选取图片");
else
MessageBox.Show("图片分析结果正确");
l.Abort();
}
}
【】
【
#region 截图方法
/// <summary>
/// 剪裁 -- 用GDI
/// </summary>
/// <param name="b">原始Bitmap</param>
/// <param name="StartX">开始坐标X</param>
/// <param name="StartY">开始坐标Y</param>
/// <param name="iWidth">宽度</param>
/// <param name="iHeight">高度</param>
/// <returns>剪裁后的Bitmap</returns>
public static Bitmap CutImage(Image b, int StartX, int StartY, int iWidth, int iHeight)
{
if (b == null)
{
return null;
}
int w = b.Width;
int h = b.Height;
Bitmap bmpOut = null;
try
{
bmpOut = new Bitmap(iWidth, iHeight);
Graphics g = Graphics.FromImage(bmpOut);
g.Clear(System.Drawing.Color.Transparent);
g.DrawImage(b, new Rectangle(0, 0, iWidth, iHeight), new Rectangle(StartX, StartY, iWidth, iHeight), GraphicsUnit.Pixel);
g.Dispose();
return bmpOut;
}
catch(Exception e)
{
MessageBox.Show(e.Message);
return null;
}
finally
{
b.Dispose();
// bmpOut.Dispose();
}
}
/// <summary>
/// 按照指定大小缩放图片,但是为了保证图片宽高比自动截取
/// </summary>
/// <param name="srcImage"></param>
/// <param name="iWidth"></param>
/// <param name="iHeight"></param>
/// <returns></returns>
public static Bitmap SizeImageWithOldPercent(Image ImageLocation1, int iWidth, int iHeight)
{
Bitmap cutedImage=null;
try
{
int newW = 1000;
int newH = 1000;
int newX = 0;
int newY = 0;
//取得符合比例的临时文件
cutedImage = CutImage(ImageLocation1, newX, newY, newW, newH);
// 保存到的文件
// Bitmap b = new Bitmap(iWidth, iHeight);
cutedImage.Save(path3, System.Drawing.Imaging.ImageFormat.Bmp);
return cutedImage;
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return null;
}
finally
{
ImageLocation1.Dispose();
cutedImage.Dispose();
}
}
#endregion
void UsingFileSystemWatcher()
{
FileSystemWatcher fswWatcher = new FileSystemWatcher();
fswWatcher.Path = path;
fswWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.LastAccess;
fswWatcher.Filter = "*.*";
fswWatcher.IncludeSubdirectories = true;
#region 实例化触发的事件(已定)
fswWatcher.Created = new FileSystemEventHandler(fswWatcher_Created);
fswWatcher.Changed = new FileSystemEventHandler(fswWatcher_Changed);
fswWatcher.Renamed = new RenamedEventHandler(fswWatcher_Renamed);
fswWatcher.Deleted = new FileSystemEventHandler(fswWatcher_Deleted);
#endregion
//获取或设置一个值,该值指示是否启用此组件。
fswWatcher.EnableRaisingEvents = true;
}//定义监控文件夹的方法
#region 监控图片传入
void fswWatcher_Created(object sender, FileSystemEventArgs e)
{
#region 修改图片名称并转存
System.Drawing.Image ImageLocation1=null;
try
{
string path2 = @"C:\copy2\" newName;
System.IO.File.Copy(e.FullPath, path2, true);
path3 = path2.Replace("copy2", "copy");
//Bitmap SizeImageWithOldPercent(Image ImageLocation1, int iWidth, int iHeight)
ImageLocation1 = System.Drawing.Image.FromFile(path2);
SizeImageWithOldPercent(ImageLocation1, ImageLocation1.Width, ImageLocation1.Height);//单独做成方法
}
catch
{
//
}
finally {
if (ImageLocation1 != null)
{
ImageLocation1.Dispose();
}
}
#endregion
}
#region 监控备用
private void ModifyFileName(string p, string p_2)
{
throw new NotImplementedException();
}
void fswWatcher_Changed(object sender, FileSystemEventArgs e)
{
}
void fswWatcher_Renamed(object sender, RenamedEventArgs e)
{
}
void fswWatcher_Deleted(object sender, FileSystemEventArgs e)
{
//DirectoryInfo dir = new DirectoryInfo(path);
//dir.Create();//自行判断一下是否存在。
}
#endregion
#endregion
private void Form1_Load(object sender, EventArgs e)
{
}
#region 皮肤算法集
private void 光泽度(object sender, EventArgs e)
{
try
{
test6.Class6 exp6 = new test6.Class6();
MWArray[] t = exp6.guangzedu(1);
MWNumericArray t1 = (MWNumericArray)t[0];
double[,] t2 = (double[,])t1.ToArray(MWArrayComponent.Real);
double t3 = t2[0, 0];
str6 = t3.ToString("N");
textBox6.Text = str6;
str6 = null;
}
catch (Exception)
{
// MessageBox.Show("图片错误,请重新选择!");
//Close();
}
finally
{
}
}
private void 粗糙度(object sender, EventArgs e)
{
try
{
test1.Class1 exp1 = new test1.Class1();
MWArray[] x = exp1.cucaodu(1);
MWNumericArray x1 = (MWNumericArray)x[0];
double[,] x2 = (double[,])x1.ToArray(MWArrayComponent.Real);
double x3 = x2[0, 0];
str1= x3.ToString("N");//将隐式int转换为string类型
textBox1.Text = str1;
str1 = null;
}
catch (Exception )
{
//MessageBox.Show("图片错误,请重新选择!");
// Close();
}
finally
{
MWArray.DisposeArray(e);
}
}
private void 纹理(object sender, EventArgs e)
{
try
{
test2.Class2 exp2 = new test2.Class2();
MWArray[] a = exp2.wenli(1);
MWNumericArray a1 = (MWNumericArray)a[0];
double[,] b2 = (double[,])a1.ToArray(MWArrayComponent.Real);
double b3 = b2[0, 0];
str2 = b3.ToString("N");
textBox2.Text = str2;
str2 = null;
}
catch (Exception )
{
// MessageBox.Show("图片错误,请重新选择!" );
// Close();
}
finally
{
MWArray.DisposeArray(e);
}
}
private void 色泽(object sender, EventArgs e)
{
try
{
test3.Class3 exp3 = new test3.Class3();
MWArray[] q = exp3.seze(1);
MWNumericArray q1 = (MWNumericArray)q[0];
double[,] q2 = (double[,])q1.ToArray(MWArrayComponent.Real);
double q3 = q2[0, 0];
str3 = q3.ToString("N");
textBox3.Text = str3;
str3 = null;
}
catch (Exception )
{
// MessageBox.Show("图片错误,请重新选择!" );
// Close();
}
finally
{
MWArray.DisposeArray(e);
}
}
private void 弹性(object sender, EventArgs e)
{
try
{
test4.Class4 exp4 = new test4.Class4();
MWArray[] w = exp4.tanxing(1);
MWNumericArray w1 = (MWNumericArray)w[0];
double[,] w2 = (double[,])w1.ToArray(MWArrayComponent.Real);
double w3 = w2[0, 0];
str4 = w3.ToString("N");
textBox4.Text = str4;
str4 = null;
}
catch (Exception )
{
// MessageBox.Show("图片错误,请重新选择!");
// Close();
}
finally
{
MWArray.DisposeArray(e);
}
}
private void 水份(object sender, EventArgs e)
{
try
{
test5.Class5 exp5 = new test5.Class5();
MWArray[] r = exp5.water(1);
MWNumericArray r1 = (MWNumericArray)r[0];
double[,] r2 = (double[,])r1.ToArray(MWArrayComponent.Real);
double r3 = r2[0, 0];
str5 = r3.ToString("N");
textBox5.Text = str5;
str5 = null;
}
catch (Exception )
{
//MessageBox.Show("图片错误,请重新选择!");
// Close();
}
finally
{
MWArray.DisposeArray(e);
}
}
#endregion
private void button2_Click_1(object sender, EventArgs e)
{
if (qq == 0)
{
Thread t = new Thread(DoWork);
t.Start();
粗糙度(sender, e);
纹理(sender, e);
色泽(sender, e);
光泽度(sender, e);
弹性(sender, e);
水份(sender, e);
str1 = null;
str2 = null;
str3 = null;
str4 = null;
str5 = null;
str6 = null;
string a = textBox6.Text.ToString();
ProgressBar1.ActiveForm.Close();
if (a == "100.00")
MessageBox.Show("光泽度有误,请重新上传!");
else if (a == "")
MessageBox.Show("结果不能为空,请重新选取图片");
else
MessageBox.Show("图片分析结果正确");
t.Abort();
qq ;
}
else
{
Thread l = new Thread(DoWork1);
l.Start();
textBox1.Text = first.ToString("G");
textBox2.Text = first.ToString("G");
textBox3.Text = first.ToString("G");
textBox4.Text = first.ToString("G");
textBox5.Text = first.ToString("G");
textBox6.Text = first.ToString("G");
粗糙度(sender, e);
纹理(sender, e);
色泽(sender, e);
光泽度(sender, e);
弹性(sender, e);
水份(sender, e);
str1 = null;
str2 = null;
str3 = null;
str4 = null;
str5 = null;
str6 = null;
string zz = textBox6.Text.ToString();
ProgressBar2.ActiveForm.Close();
if (zz == "100.00")
MessageBox.Show("光泽度有误,请重新上传!");
else if (zz == "")
MessageBox.Show("结果不能为空,请重新选取图片");
else
MessageBox.Show("图片分析结果正确");
l.Abort();
}
}
代码片段和文件信息
- 上一篇:c#皮肤控件
- 下一篇:从exe文件中提取图标
相关资源
- C# 水平交错效果显示图像
- winform 垂直交错效果显示图像
- winform 浮雕效果的图像
- c# 底片效果显示图像就像旧式相机的
- 积木效果显示图像
- browerPhotoC#网页截图(不打开网页)
- C#图像处理效果(浮雕/黑白/柔化/锐化
- 控制台 ProgressBar进度条
- 图像填充文字(垂直显示/水平显示文
- html5简单进度条效(progressbar)
- vb 具有预览功能的图像查看器用户控
- 具有预览功能的图像查看器用户控件
- C# 文本图像旋转(TransformRotate)
- 根据文件大小显示文件复制进度条
- 弹出模式窗口显示进度条
- 批量图像格式转换
- Progressbar进度条控件
- wpf自定义进度条
-
AForge.NET_fr
amework-2.1.3 一个C#下面的图 - image_segmentation C#实现图像分割
- CSharp-read-tiff C#读取TIF格式的图像
- EmgucvTest 用c#和emgucv实现了1.显示图像
- com 图像处理算法
- digital C#编写的图像处理程序源码 一共
- C# 图像放大与缩小
- C#图像热区识别
- c#实现边缘检测源码
- C#写的图像处理函数,椒盐噪声,中值
- 文件传输,大文件分包传输,含进度
- C# ASP.NET 图片批量上传,可预览带进度
评论
共有 条评论