学习FotoVision 进行C# colorMatrix 对图片的处理 : 亮度调整 抓屏 翻转 随鼠标画矩形
2008-09-10 13:52
537 查看
0.FotoVision下载地址
http://www.microsoft.com/downloads/details.aspx?FamilyId=D4738DCA-E95C-4D4F-BF32-00A865006C73&displaylang=en
1.图片亮度处理
private void trackBar1_ValueChanged(object sender, EventArgs e)
{
//this.numericUpDown1.Value = this.trackBar1.Value;
int percent = this.trackBar1.Value;
Single v = 0.006F * percent;
Single[][] matrix = {
new Single[] { 1, 0, 0, 0, 0 },
new Single[] { 0, 1, 0, 0, 0 },
new Single[] { 0, 0, 1, 0, 0 },
new Single[] { 0, 0, 0, 1, 0 },
new Single[] { v, v, v, 0, 1 }
};
System.Drawing.Imaging.ColorMatrix cm = new System.Drawing.Imaging.ColorMatrix(matrix);
System.Drawing.Imaging.ImageAttributes attr = new System.Drawing.Imaging.ImageAttributes();
attr.SetColorMatrix(cm);
//Image tmp
Image tmp = Image.FromFile(@"F://ImageManager/images/1.jpg");
Graphics g = Graphics.FromImage(tmp);
try
{
Rectangle destRect = new Rectangle(0, 0, tmp.Width, tmp.Height);
g.DrawImage(tmp, destRect, 0, 0, tmp.Width, tmp.Height, GraphicsUnit.Pixel, attr);
}
finally
{
g.Dispose();
}
this.pictureBox1.Image = tmp;
}
2.抓屏将生成的图片显示在pictureBox
private void button1_Click(object sender, EventArgs e)
{
Image myImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics g = Graphics.FromImage(myImage);
g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height));
IntPtr dc1 = g.GetHdc();
g.ReleaseHdc(dc1);
g.Dispose();
this.pictureBox1.Image = myImage;
}
3.翻转
private void button3_Click(object sender, EventArgs e)
{
Image tmp = this.pictureBox1.Image;
tmp.RotateFlip(RotateFlipType.Rotate90FlipNone);
this.pictureBox1.Image = tmp;
}
4.跟随鼠标在 pictureBox的图片上画矩形
private int intStartX = 0;
private int intStartY = 0;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (isMouseDraw)
{
isMouseDraw = false;
//MessageBox.Show("禁用随鼠标画图");
}
else
{
isMouseDraw = true;
//MessageBox.Show("启用随鼠标画图");
}
if (isMouseDraw)
{
intStartX = e.X;
intStartY = e.Y;
}
else
{
intStartX = 0;
intStartY = 0;
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDraw)
{
try
{
Image tmp = Image.FromFile(@"F://ImageManager/images/1.jpg");
Graphics g = Graphics.FromImage(tmp);
Brush brush = new SolidBrush(Color.Red);
Pen pen = new Pen(brush, 1);
pen.DashStyle = DashStyle.Solid;
g.DrawRectangle(pen, new Rectangle(intStartX > e.X ? e.X : intStartX, intStartY > e.Y ? e.Y : intStartY, Math.Abs(e.X - intStartX), Math.Abs(e.Y - intStartY)));
g.Dispose();
this.pictureBox1.Image = tmp;
}
catch (Exception ex)
{
ex.ToString();
}
}
}
http://www.microsoft.com/downloads/details.aspx?FamilyId=D4738DCA-E95C-4D4F-BF32-00A865006C73&displaylang=en
1.图片亮度处理
private void trackBar1_ValueChanged(object sender, EventArgs e)
{
//this.numericUpDown1.Value = this.trackBar1.Value;
int percent = this.trackBar1.Value;
Single v = 0.006F * percent;
Single[][] matrix = {
new Single[] { 1, 0, 0, 0, 0 },
new Single[] { 0, 1, 0, 0, 0 },
new Single[] { 0, 0, 1, 0, 0 },
new Single[] { 0, 0, 0, 1, 0 },
new Single[] { v, v, v, 0, 1 }
};
System.Drawing.Imaging.ColorMatrix cm = new System.Drawing.Imaging.ColorMatrix(matrix);
System.Drawing.Imaging.ImageAttributes attr = new System.Drawing.Imaging.ImageAttributes();
attr.SetColorMatrix(cm);
//Image tmp
Image tmp = Image.FromFile(@"F://ImageManager/images/1.jpg");
Graphics g = Graphics.FromImage(tmp);
try
{
Rectangle destRect = new Rectangle(0, 0, tmp.Width, tmp.Height);
g.DrawImage(tmp, destRect, 0, 0, tmp.Width, tmp.Height, GraphicsUnit.Pixel, attr);
}
finally
{
g.Dispose();
}
this.pictureBox1.Image = tmp;
}
2.抓屏将生成的图片显示在pictureBox
private void button1_Click(object sender, EventArgs e)
{
Image myImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics g = Graphics.FromImage(myImage);
g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height));
IntPtr dc1 = g.GetHdc();
g.ReleaseHdc(dc1);
g.Dispose();
this.pictureBox1.Image = myImage;
}
3.翻转
private void button3_Click(object sender, EventArgs e)
{
Image tmp = this.pictureBox1.Image;
tmp.RotateFlip(RotateFlipType.Rotate90FlipNone);
this.pictureBox1.Image = tmp;
}
4.跟随鼠标在 pictureBox的图片上画矩形
private int intStartX = 0;
private int intStartY = 0;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (isMouseDraw)
{
isMouseDraw = false;
//MessageBox.Show("禁用随鼠标画图");
}
else
{
isMouseDraw = true;
//MessageBox.Show("启用随鼠标画图");
}
if (isMouseDraw)
{
intStartX = e.X;
intStartY = e.Y;
}
else
{
intStartX = 0;
intStartY = 0;
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDraw)
{
try
{
Image tmp = Image.FromFile(@"F://ImageManager/images/1.jpg");
Graphics g = Graphics.FromImage(tmp);
Brush brush = new SolidBrush(Color.Red);
Pen pen = new Pen(brush, 1);
pen.DashStyle = DashStyle.Solid;
g.DrawRectangle(pen, new Rectangle(intStartX > e.X ? e.X : intStartX, intStartY > e.Y ? e.Y : intStartY, Math.Abs(e.X - intStartX), Math.Abs(e.Y - intStartY)));
g.Dispose();
this.pictureBox1.Image = tmp;
}
catch (Exception ex)
{
ex.ToString();
}
}
}
相关文章推荐
- 学习FotoVision 进行C# colorMatrix 对图片的处理 : 亮度调整 抓屏 翻转 随鼠标画矩形
- C#图像处理(各种旋转、改变大小、柔化、锐化、雾化、底片、浮雕、黑白、滤镜效果,滤波,图像截取) 对图片的处理 : 亮度调整 抓屏 翻转 随鼠标画矩形
- iOS中对图片的处理(对图片进行滤镜处理、调整图片饱和度、亮度、对比度、创建一张实时模糊效果 View (毛玻璃效果)、截取一张 view 生成图片)
- 使用python进行图像处理-调整图片大小
- 【数字图像处理】使用kmeans算法对TrueColor图片进行优化
- Win8Metro(C#)数字图像处理--2.5图像亮度调整
- 对图片进行切片处理,对BitBlt()方法的研究心得--c#
- C# 图像处理:实现鼠标选择矩形截图
- iOS-Opencv 基础学习四(对图片进行图像模糊处理blur、边缘处理Canny)
- 【OpenCV学习】Kmean均值聚类对图片进行减色处理
- OpenCV学习八:图片的亮度对比度调整
- Android图片处理(Matrix,ColorMatrix)
- Android图片处理(Matrix,ColorMatrix)
- c#图片色阶调整、亮度调整
- C#对图片进行马赛克处理,可控制模糊程度
- Android图片处理(Matrix,ColorMatrix)
- 对图片进行缩放处理——Matrix对象的使用
- 【OpenCV学习】Kmean均值聚类对图片进行减色处理
- tensorflow下有关图片的随机翻转、随机调整亮度以及对比度函数
- android学习之对照相的图片进行处理学习