g.DrawImage(newImage, new System.Drawing.Rectangle(0, 0, towidth, toheight), new System.Drawing.Rectangle(x, y, ow, oh), System.Drawing.GraphicsUnit.Pixel);这句后面加上g.DrawRectangle(new Pen(Color.Green,2),1,1,ow-1,oh-1);看看是不是你要的边框效果。每次绘制之前在原图片上加上边框再绘制就行了。
下面贴出代码: C# code public partial class EditPhoto : Form { private Rectangle m_Rect; private Point m_LastMsPoint; private Point m_LastRect…… [/Quote] 这个有点靠谱
float[][] nArray ={ new float[] {1, 0, 0, 0, 0},
new float[] {0, 1, 0, 0, 0},
new float[] {0, 0, 1, 0, 0},
new float[] {0, 0, 0, opacity, 0},
new float[] {0, 0, 0, 0, 1}
}; while (opacity < 1) {
opacity += 0.1F;
nArray[3][3] = opacity;
ColorMatrix matrix = new ColorMatrix(nArray);
ImageAttributes attributes = new ImageAttributes();
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
Bitmap resultImage = new Bitmap(img.Width, img.Height);
Graphics g = Graphics.FromImage(resultImage);
g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, attributes);
pPicBox.Image.Dispose();
pPicBox.Image = resultImage;
Thread.Sleep(100);
}
在onPaint()事件里绘图
(1)绘图用drawbitmap
(2)绘矩形什么的用drawrectangle
再做鼠标事件控制就可以了,不用搞什么透明不透明的
{ private Rectangle m_Rect;
private Point m_LastMsPoint;
private Point m_LastRectPoint;
private bool m_CanMove;
int mouseflag = 0;
Cursor m_oldCursor = default(Cursor); public EditPhoto()
{
InitializeComponent();
m_Rect = new Rectangle(10, 10, 50, 25);
}
string Path = "\\photo\\";
private void EditPhoto_Load(object sender, EventArgs e)
{
pictureBox1.ImageLocation = Application.StartupPath + Path + "1" + ".bmp";
//pictureBox1.ImageLocation = CanPhotosForm.picurl;
} private void btnxuanqu_Click(object sender, EventArgs e)
{
Image newImage = pictureBox1.Image;
int towidth = m_Rect.Width;
int toheight = m_Rect.Height;
int x = m_Rect.X;
int y = m_Rect.Y;
int ow = m_Rect.Width;
int oh = m_Rect.Height;
System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight); //新建一个画板
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap); //设置高质量插值法
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //清空画布并以透明背景色填充
g.Clear(System.Drawing.Color.Transparent); //在指定位置并且按指定大小绘制原图片的指定部分
g.DrawImage(newImage, new System.Drawing.Rectangle(0, 0, towidth, toheight),
new System.Drawing.Rectangle(x, y, ow, oh),
System.Drawing.GraphicsUnit.Pixel); try
{
//以jpg格式保存缩略图
bitmap.Save(Application.StartupPath + Path + textBox1.Text + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (Exception ex)
{
}
finally
{
//newImage.Dispose();
bitmap.Dispose();
g.Dispose();
} } private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawRectangle(SystemPens.HotTrack, this.m_Rect);
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
#region zhege
Rectangle rect_left = new Rectangle(m_Rect.Left - 2, m_Rect.Top + 2, 4, m_Rect.Height - 4);
Rectangle rect_right = new Rectangle(m_Rect.Right - 2, m_Rect.Top + 2, 4, m_Rect.Height - 4);
Rectangle rect_top = new Rectangle(m_Rect.Left + 2, m_Rect.Top - 2, m_Rect.Width - 4, 4);
Rectangle rect_bottom = new Rectangle(m_Rect.Left + 2, m_Rect.Bottom - 2, m_Rect.Width - 4, 4);
Rectangle rect_rb = new Rectangle(m_Rect.Right - 2, m_Rect.Bottom - 2, 4, 4);
if (m_Rect.Contains(e.Location))
{
m_CanMove = false;
}
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
if (mouseflag != 0)
{
switch (mouseflag)
{
case 4:
this.m_Rect = new Rectangle(e.X, m_Rect.Top, m_Rect.Right - e.X, m_Rect.Height);
break; case 6:
this.m_Rect.Width = e.X - m_Rect.Left;
break; case 8:
this.m_Rect.Height = m_Rect.Bottom - e.Y;
m_Rect.Location = new Point(m_Rect.Left, e.Y);
break; case 2:
this.m_Rect.Height = e.Y - m_Rect.Top;
break; case -1:
this.m_Rect.Width = e.X - m_Rect.Left;
this.m_Rect.Height = e.Y - m_Rect.Top;
break;
case 5:
int x = m_LastRectPoint.X + e.X - this.m_LastMsPoint.X;
int y = m_LastRectPoint.Y + e.Y - this.m_LastMsPoint.Y;
this.m_Rect.Location = new Point(x, y);
break;
default:
break;
} }
m_Rect.Height = m_Rect.Width * 2;
this.pictureBox1.Invalidate();
this.pictureBox2.Invalidate();
}
else
{
if (rect_left.Contains(e.Location))
{
this.Cursor = Cursors.SizeWE; //向右
this.mouseflag = 4;
}
else if (rect_right.Contains(e.Location))
{
this.Cursor = Cursors.SizeWE; //向左
this.mouseflag = 6;
}
else if (rect_top.Contains(e.Location))
{
this.Cursor = Cursors.SizeNS; //向上;
this.mouseflag = 8;
}
else if (rect_bottom.Contains(e.Location))
{
this.Cursor = Cursors.SizeNS; //向下;
this.mouseflag = 2;
}
else if (m_Rect.Contains(e.Location))
{
this.Cursor = Cursors.SizeAll;
mouseflag = 5;
}
else if (rect_rb.Contains(e.Location))
{
this.Cursor = Cursors.SizeNWSE;
mouseflag = -1;
}
else
{
this.Cursor = m_oldCursor;
mouseflag = 0;
} }
#endregion
} private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
m_LastMsPoint = e.Location;
m_LastRectPoint = m_Rect.Location;
m_CanMove = this.m_Rect.Contains(e.Location);
} private void pictureBox2_Paint(object sender, PaintEventArgs e)
{
if (pictureBox1.Image !=null )
{
Rectangle rect = new Rectangle(0, 0, this.m_Rect.Width, this.m_Rect.Height);
e.Graphics.DrawImage(this.pictureBox1.Image, rect, this.m_Rect, GraphicsUnit.Pixel);
}
} }
new System.Drawing.Rectangle(x, y, ow, oh),
System.Drawing.GraphicsUnit.Pixel);这句后面加上g.DrawRectangle(new Pen(Color.Green,2),1,1,ow-1,oh-1);看看是不是你要的边框效果。每次绘制之前在原图片上加上边框再绘制就行了。
vb中基本图形控件,从vs2002就有。运行时进行拖拉,是自己捕获鼠标事件来实现的。难道你弄个透明Panel,就能不编写任何代码而拖拉了?
但在我的认知中,摄像头的数据是利用驱动直接输出到屏幕的。
因此,使用任何遮盖性的办法都不是可取的。
只有从摄像头中取出数据的时候,也就是取出一张张图片的时候,
在那个上面是可以随意处理的,加文字,画框都没有问题。(亲手做过)所以,要使用DirectShow来做,这样是可以成功的。
在onPaint()事件里绘图
(1)绘图用drawbitmap
(2)绘矩形什么的用drawrectangle
再做鼠标事件控制就可以了
C# code public partial class EditPhoto : Form
{ private Rectangle m_Rect;
private Point m_LastMsPoint;
private Point m_LastRect……
[/Quote] 这个有点靠谱
关键是怎么采用DirectShow来做??其实有些工业摄像机自带的sdk会自带overlay的方法,用这个方法能在上面画东西,其他的不行!!