b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

C#画图解决闪烁问题(2)

电脑杂谈  发布时间:2019-08-06 00:02:41  来源:网络整理

{

if (e.Button == MouseButtons.Right) return;

p = e.Location;

}

private void picturebox1_mousemove(object sender, mouseeventargs e)。private void mh_onmousedownevent(object sender, mouseeventargs e)。private void subclassedgridview_mousedown(object sender, mouseeventargs e)。

{

if (e.Button == MouseButtons.Right) return;

location.X += e.X - p.X;

location.Y += e.Y - p.Y;

p = Point.Empty;

}

private void picturebox1_mousemove(object sender, mouseeventargs e)。private void mh_onmousedownevent(object sender, mouseeventargs e)。private void subclassedgridview_mousedown(object sender, mouseeventargs e)。

{

if (p == Point.Empty) return;

x = e.X - p.X + location.X;

y = e.Y - p.Y + location.Y;

this.Invalidate(true);//触发Paint事件

}

}

这个简单的例子实现了用鼠标拖动窗口中矩形,利用双缓冲技术使过程不会产生闪烁.

在这个例子上我犯的错误:

在 OnPaint(PaintEventArgs e)中,我使用下面两种方法获取graphics 对象

Graphics g = this.CreateGraphics();

Graphics g = Graphics.FromHwnd(this.Handle);

这都使双缓冲失效.

获得graphics 对象还有两种方法是

Graphics g = Graphics.FromImage(image); //后面将用此方法实现双缓冲

透明尼龙板_画图工具怎么改图片文字背景不变_画图板 背景透明

Graphics g = e.Graphics; //这是唯一好使的方法

上面是在Form窗口直接绘制图形,那么如何在控件上(比如Panel)利用双缓冲技术绘图呢?

在窗口窗创建一个Panel , 并修改一下代码

private void panel1_Paint(object sender, PaintEventArgs e)

{

Graphics g = e.Graphics;

g.FillRectangle(Brushes.Black, x, y, 200, 200);

}

运行后发现拖动在panel1上绘制的图形依然有闪烁,那么是不是应该这样设置

this.setstyle(controlstyles.doublebuffer | controlstyles.allpaintinginwmpaint, true)。 controlstyles.resizeredraw, true)。or:true and unknown 的结果是true,false and unknown 的结果是unknown,unknown and unknown 的结果是unknown。

因为SetStyle()在Panel类中不是public方法

使用从Panel类继承的MyPanel类 的构造函数中设置双缓冲

public class MyPanel:Panel

{

public MyPanel()

{

this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);

this.SetStyle(ControlStyles.UserPaint, true);

}

}

不管怎么说这个方法的确好用,不过注意以后你使用的是MyPanel类,而不是Panel.

把自己定义MyPanel从工具栏里拖到窗口上和Panle一样使用.

注意:在控件上绘制就必须设置该控件的DoubleBuffer,而不是Form的DoubleBuffer.

在此之前我采用自己的方法实现双缓冲而不是控件自身的DoubleBuffer

先在内存里绘制图形,包括清除旧画面和绘制新画面,然后将内存的图形绘制到屏幕上

public void Draw(System.Windows.Forms.Panel _panel, float _x, float _y)

{

Graphics g = Graphics.FromHwnd(_panel.Handle);

try{

//在内存创建一块和panel一大小的区域

system.drawing.bitmap destbmp = new bitmap(srcbmp.width, srcbmp.height)。 bitmap bitmap = bitmap.createbitmap(mbitmap,0,0,width,height,matrix,true)。bitmap maskimage = new bitmap (width, height)。

using (Graphics buffer = Graphics.FromImage(bitmap))

{

//buffer中绘图

buffer.Clear(_panel.BackColor); //用背景色填充画面

buffer.Transform = matrix;

【例 6】 y = e x cos x ,求 y ′′′ . 解: y ′ = e x cos x + e x ( sin x) = e x (cos x sin x) , y ′′ = e x (cos x sin x) + e x ( sin x cos x) = e x (2 sin x) , y ′′′ = 2(e x sin x + e x cos x) = 2e x (sin x + cos x) .。3.根据权利要求i所述的基于直方图匹配和sad判决的dmvc边信息融合方法,其特征在于所述步骤(i)中最小绝对误差和采用如下计算公式sad(i, j) = x z l7 -1 (x,y) - 7 +1 (x + i^ + ))1x=i y=l式中,(i,j)是运动矢量,ilri(x,y)和in+1(x+i,y+j)分别是前、后关键帧位于(x,y) 和(x+i, y+j)处的像素值,m = n = 8是图像块的大小。 polytool(x,y,m,alpha)3 4 5 6 7 8 9 10 11 12500600700800900100011001200例 例1的交互式画面注意的交互式画面注意3个程序的用法与所得结果的相同点和不同点个程序的用法与所得结果的相同点和不同点非线性回归分析非线性最小二乘拟合) , , ( ), , , ( ), , (1 1 k mx x x x f y &beta。

//屏幕绘图

g.DrawImage(bitmap, 0, 0); //将buffer绘制到屏幕上

}

}

finally

画图板 背景透明_画图工具怎么改图片文字背景不变_透明尼龙板

{

g.Dispose();

}

}

使用上面方法不需要任何设置.

总结一下

与绘图有关的ControlStyles

enum ControlStyles{

AllPainingInWmPaint, //将绘制阶段折叠入Paint事件

DoubleBuffer, //直到Paint返回,再显示绘制对象

UserPaint, //用于自身有着特别绘制的控件

Opaque, //忽略OnPaintBackground,Paint事件绘制整个区域

ResizeRedraw,//当调整控件大小时使整个工作区无效

SupportsTransparentBackColor,//模拟透明控件

...

}

1.在OnPaint(PaintEventArgs e)或Paint中 使用e获取graphics,我之所以费了很大周折就是因为在网上找到一篇实现双缓冲文章介绍,不要使用e获取graphics,而用this.CreateGraphics(),还有的文章介绍了奇怪的方法居然最终也好使.

2.在继承了Form和control 的控件上利用双缓冲绘制的时候,可以在控件的构造函数里设置双缓冲属性,而在窗口Form 里设置doublebuffer,只针对窗口的绘制起作用.

3.使用自己的方法,双缓冲的原理都是一样的.

示例:

private void DrawRectBackImage()

{

Graphics g = Graphics.FromHwnd(_currentChart.Handle);

try

{

//在内存创建一块和panel一大小的区域

Bitmap bitmap = new Bitmap(_currentChart.ClientSize.Width, _currentChart.ClientSize.Height);

using (Graphics buffer = Graphics.FromImage(bitmap))

{

buffer.Transform =new Matrix();

//要画的背景图片

objects = main.o kbd.o command.o display.o \insert.o search.o files.o utils.oedit : $(objects)cc -o edit $(objects)main.o : defs.hkbd.o : defs.h command.hcommand.o : defs.h command.hdisplay.o : defs.h buffer.hinsert.o : defs.h buffer.hsearch.o : defs.h buffer.hfiles.o : defs.h buffer.h command.hutils.o : defs.h.phony : cleanclean :rm edit $(objects)。vertex buffer object\vertex array object\uniform buffer\texture buffer\pixel pack buffer\pixel unpack buffer。memory mapped buffer mode and user pointer buffer mode are the two memory allocation modes supported by driver. in memory map buffer mode, application can request memory from the driver by calling vidioc_reqbufs ioctl. in this mode, maximum number of buffers is limited to video_max_frame (defined in driver header files) and is limited by the available memory in the kernel. if driver is not able to allocate the requested number of buffer, it will return the number of buffer it is able to allocate.。

//背景图片上的内容

DrawFitAdjustRect(buffer);

//屏幕绘图

g.DrawImage(bitmap, 0, 0); //将buffer绘制到屏幕上

}

}

finally

{

g.Dispose();

}

}


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/ruanjian/article-118200-2.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...