如何根据颜色值来显示该颜色值区域 各位大侠 最近编写一个用来取色软件 用WINDOWS图片和传真查看器中显示的图片,根据图片中黑色(#FFFFFF)来选取以黑色为主的区域(轮廓),将其区域保存在C:\white.bmp下。各位大侠,请问有什么办法可以实现呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 说一下思路 你要求的功能是不是QQ截图所要实现的功能是的话 继续向下看因为近来想写个类似于远程桌面监控的程序,该程序中要用到屏幕捕捉.为实现该程序的一部分功能,做了个小DEMO.程序很简单,用到的技术也不多,只能实现类似qq的截图功能(方法虽然很笨)程序流程如下: 字串3 字串51.截取整个屏幕并保存2.新开一个全屏窗口,将保存的屏幕作为背景3.鼠标拖动改变截取范围,右键取消4.双击截取,保存在粘贴板,全屏窗口关闭 字串3 字串4好了,下面的是代码部分 字串9 字串5首先新建一个项目ScreenCutter(VS2005),将窗体名改为MainForm,再新建一个窗体ScreenBody.添加一个按钮btnCutter到ScreenCutter并添加按钮事件: private void btnCutter_Click(object sender, EventArgs e) { Image img = new Bitmap(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height); Graphics g = Graphics.FromImage(img); g.CopyFromScreen(new Point(0, 0), new Point(0, 0), Screen.AllScreens[0].Bounds.Size); ScreenBody body = new ScreenBody(); body.BackgroundImage = img; body.Show(); 字串8 }Screen.AllScreens[0]是获取当前所有设备窗口的第一个,我这里只有一个显示器,当然我就是第一个.利用Graphics的CopyFromScreen函数获取当前屏幕. 字串5好了,现在按下按钮全屏窗口就会出来了. 字串1下面讲全屏窗口ScreenBody,首先设置窗体的FormBorderStyle为None,然后声明以下变量private Graphics MainPainter; //主画笔private Pen pen; //就是笔咯private bool isDowned; //判断鼠标是否按下private bool RectReady; //矩形是否绘制完成private Image baseImage; //基本图形(原来的画面)private Rectangle Rect; //就是要保存的矩形private Point downPoint; //鼠标按下的点int tmpx; int tmpy;之后就是窗体的鼠标函数了,里面很多代码都没有作出整理,看了一下,整理后的代码应该会更少更精简的 字串9 private void ScreenBody_DoubleClick(object sender, EventArgs e){ if (((MouseEventArgs)e).Button == MouseButtons.Left &&Rect.Contains(((MouseEventArgs)e).X, ((MouseEventArgs)e).Y)) { //保存的时候有很多种方法的......我这里只用了这种 Image memory = new Bitmap(Rect.Width, Rect.Height); Graphics g = Graphics.FromImage(memory); g.CopyFromScreen(Rect.X + 1, Rect.Y + 1, 0, 0, Rect.Size); Clipboard.SetImage(memory); this.Close(); }} 字串6private void ScreenBody_MouseDown(object sender, MouseEventArgs e){ if (e.Button == MouseButtons.Left) { isDowned = true; if (RectReady == false) { Rect.X = e.X; Rect.Y = e.Y; downPoint = new Point(e.X, e.Y); } if (RectReady == true) { tmpx = e.X; tmpy = e.Y; } 字串2 } if (e.Button == MouseButtons.Right) { if (RectReady != true) { this.Close(); return; } MainPainter.DrawImage(baseImage, 0, 0); RectReady = false; } } private void ScreenBody_MouseUp(object sender, MouseEventArgs e){ if (e.Button == MouseButtons.Left) { isDowned = false; RectReady = true; }} 字串3 private void ScreenBody_MouseMove(object sender, MouseEventArgs e) 字串8 { 字串7 if (RectReady == false) { if (isDowned == true) { Image New = DrawScreen((Image)baseImage.Clone(), e.X, e.Y); MainPainter.DrawImage(New, 0, 0); New.Dispose(); } } if (RectReady == true) { if (Rect.Contains(e.X, e.Y)) { //this.Cursor = Cursors.Hand; if (isDowned == true) { 字串6 //和上一次的位置比较获取偏移量 Rect.X = Rect.X + e.X - tmpx; Rect.Y = Rect.Y + e.Y - tmpy; //记录现在的位置 tmpx = e.X; tmpy = e.Y; MoveRect((Image)baseImage.Clone(), Rect); } } } 字串8} private void ScreenBody_Load(object sender, EventArgs e){ this.WindowState = FormWindowState.Maximized; MainPainter = this.CreateGraphics(); pen = new Pen(Brushes.Blue); isDowned = false; baseImage = this.BackgroundImage; Rect = new Rectangle(); RectReady = false;} 字串6辅助函数本来应该写更多的辅助函数的,将窗体响应函数里面的代码放到里面来,不过本人很懒,就这样将就了.呵呵 字串3 private void DrawRect(Graphics Painter, int Mouse_x, int Mouse_y){ int width = 0; int heigth = 0; if (Mouse_y < Rect.Y) { Rect.Y = Mouse_y; heigth = downPoint.Y - Mouse_y; } else { heigth = Mouse_y - downPoint.Y; } if (Mouse_x < Rect.X) { Rect.X = Mouse_x; width = downPoint.X - Mouse_x; } else { width = Mouse_x - downPoint.X; } Rect.Size = new Size(width, heigth); 字串8 Painter.DrawRectangle(pen, Rect);} private Image DrawScreen(Image back, int Mouse_x, int Mouse_y){ Graphics Painter = Graphics.FromImage(back); DrawRect(Painter, Mouse_x, Mouse_y); return back;}private void MoveRect(Image image, Rectangle Rect){ Graphics Painter = Graphics.FromImage(image); Painter.DrawRectangle(pen, Rect.X, Rect.Y, Rect.Width, Rect.Height); DrawRects(Painter); MainPainter.DrawImage(image, 0, 0); image.Dispose();} 字串9 并不是QQ的截图功能,和PHOTOSHOP中的套索工具一样的功能,只不过是将其选择的颜色值的颜色的区域加载入内存然后将其(区域轮廓)保存在一个文件中(c:\white.bmp),请问有什么办法呢?例如一幅图片中有黑色的部分全部拷贝入内存(赋予变量A),然后将A(隐藏式的画图软件)保存入c:\white.bmp我要将上图中的绿色部分保存到c:\white.bmp 图片没有显示成功,图片的URL在http://db.xinwen520.net/1258.bmp 图片没有显示成功CSDN的大侠们,帮帮忙!!多谢!! 内存 和 硬盘有甚么区别嘛?? 你用Cbitmap 类实现一个对象 不就完了 大佬我用的是VB,不是VC++VB中真的没有牛人了吗? 发送邮件,在线等待! VB OCX控件,控件注册 如何一次性删除复选后的某一项选择,不是一个字一个字的删除 vb 在XP环境下,如何真正隐藏进程或者不允许在任务管理器结束 机箱外若提供eSATA接口,它应该是什么样的,有几根针 在vb.net中能建立标准.dll文件吗? WebBrowser控件可以不下载图片吗? VB保存问题!看看呀 有关目录删除的问题,谁能解决这个问题我给300分(还可以加),建议、up也有分 用ado 还是 dao阿? VB自定义函数调用! 一个简单的2表关联的问题,还请指教
你要求的功能是不是QQ截图所要实现的功能是的话 继续向下看
因为近来想写个类似于远程桌面监控的程序,该程序中要用到屏幕捕捉.为实现该程序的一部分功能,做了个小DEMO.程序很简单,用到的技术也不多,只能实现类似qq的截图功能(方法虽然很笨)
程序流程如下: 字串3 字串5
1.截取整个屏幕并保存
2.新开一个全屏窗口,将保存的屏幕作为背景
3.鼠标拖动改变截取范围,右键取消
4.双击截取,保存在粘贴板,全屏窗口关闭 字串3
字串4好了,下面的是代码部分 字串9 字串5
首先新建一个项目ScreenCutter(VS2005),将窗体名改为MainForm,再新建一个窗体ScreenBody.
添加一个按钮btnCutter到ScreenCutter并添加按钮事件:
private void btnCutter_Click(object sender, EventArgs e)
{
Image img = new Bitmap(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height);
Graphics g = Graphics.FromImage(img);
g.CopyFromScreen(new Point(0, 0), new Point(0, 0), Screen.AllScreens[0].Bounds.Size);
ScreenBody body = new ScreenBody();
body.BackgroundImage = img;
body.Show(); 字串8 }Screen.AllScreens[0]是获取当前所有设备窗口的第一个,我这里只有一个显示器,当然我就是第一个.
利用Graphics的CopyFromScreen函数获取当前屏幕.
字串5
好了,现在按下按钮全屏窗口就会出来了. 字串1
下面讲全屏窗口ScreenBody,首先设置窗体的FormBorderStyle为None,然后声明以下变量
private Graphics MainPainter; //主画笔
private Pen pen; //就是笔咯
private bool isDowned; //判断鼠标是否按下
private bool RectReady; //矩形是否绘制完成
private Image baseImage; //基本图形(原来的画面)
private Rectangle Rect; //就是要保存的矩形
private Point downPoint; //鼠标按下的点
int tmpx;
int tmpy;
之后就是窗体的鼠标函数了,里面很多代码都没有作出整理,看了一下,整理后的代码应该会更少更精简的 字串9 private void ScreenBody_DoubleClick(object sender, EventArgs e)
{
if (((MouseEventArgs)e).Button == MouseButtons.Left &&Rect.Contains(((MouseEventArgs)e).X, ((MouseEventArgs)e).Y))
{
//保存的时候有很多种方法的......我这里只用了这种
Image memory = new Bitmap(Rect.Width, Rect.Height);
Graphics g = Graphics.FromImage(memory);
g.CopyFromScreen(Rect.X + 1, Rect.Y + 1, 0, 0, Rect.Size);
Clipboard.SetImage(memory);
this.Close();
}
} 字串6
private void ScreenBody_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isDowned = true;
if (RectReady == false)
{
Rect.X = e.X;
Rect.Y = e.Y;
downPoint = new Point(e.X, e.Y);
}
if (RectReady == true)
{
tmpx = e.X;
tmpy = e.Y;
} 字串2 }
if (e.Button == MouseButtons.Right)
{
if (RectReady != true)
{
this.Close();
return;
}
MainPainter.DrawImage(baseImage, 0, 0);
RectReady = false;
}
}
private void ScreenBody_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isDowned = false;
RectReady = true;
}
} 字串3
private void ScreenBody_MouseMove(object sender, MouseEventArgs e) 字串8
{ 字串7 if (RectReady == false)
{
if (isDowned == true)
{
Image New = DrawScreen((Image)baseImage.Clone(), e.X, e.Y);
MainPainter.DrawImage(New, 0, 0);
New.Dispose();
}
}
if (RectReady == true)
{
if (Rect.Contains(e.X, e.Y))
{
//this.Cursor = Cursors.Hand;
if (isDowned == true)
{ 字串6
//和上一次的位置比较获取偏移量
Rect.X = Rect.X + e.X - tmpx;
Rect.Y = Rect.Y + e.Y - tmpy;
//记录现在的位置
tmpx = e.X;
tmpy = e.Y;
MoveRect((Image)baseImage.Clone(), Rect);
}
}
}
字串8
}
private void ScreenBody_Load(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
MainPainter = this.CreateGraphics();
pen = new Pen(Brushes.Blue);
isDowned = false;
baseImage = this.BackgroundImage;
Rect = new Rectangle();
RectReady = false;
} 字串6辅助函数
本来应该写更多的辅助函数的,将窗体响应函数里面的代码放到里面来,不过本人很懒,就这样将就了.呵呵 字串3 private void DrawRect(Graphics Painter, int Mouse_x, int Mouse_y)
{
int width = 0;
int heigth = 0;
if (Mouse_y < Rect.Y)
{
Rect.Y = Mouse_y;
heigth = downPoint.Y - Mouse_y;
}
else
{
heigth = Mouse_y - downPoint.Y;
}
if (Mouse_x < Rect.X)
{
Rect.X = Mouse_x;
width = downPoint.X - Mouse_x;
}
else
{
width = Mouse_x - downPoint.X;
}
Rect.Size = new Size(width, heigth); 字串8
Painter.DrawRectangle(pen, Rect);
}
private Image DrawScreen(Image back, int Mouse_x, int Mouse_y)
{
Graphics Painter = Graphics.FromImage(back);
DrawRect(Painter, Mouse_x, Mouse_y);
return back;
}
private void MoveRect(Image image, Rectangle Rect)
{
Graphics Painter = Graphics.FromImage(image);
Painter.DrawRectangle(pen, Rect.X, Rect.Y, Rect.Width, Rect.Height);
DrawRects(Painter);
MainPainter.DrawImage(image, 0, 0);
image.Dispose();
} 字串9
例如一幅图片中有黑色的部分全部拷贝入内存(赋予变量A),然后将A(隐藏式的画图软件)保存入c:\white.bmp我要将上图中的绿色部分保存到c:\white.bmp
多谢!!
你用Cbitmap 类实现一个对象 不就完了
我用的是VB,不是VC++
VB中真的没有牛人了吗?