在漫游文本中不必要的闪烁 [英] unwanted flickers in anamated text

查看:76
本文介绍了在漫游文本中不必要的闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hellow

i我试图对其文字大小为200的文章进行分析,但它的工作原理却让我注意到字母闪烁。我尝试使用2种不同颜色的束带

(白色擦除字符串然后红色绘制字符串),我也做了类似的事情使用图像jpg但没有差异

任何建议或如果你知道任何其他方法

计时器tm =  Timer(); 
图片imageFile;
PointF po;
Graphics g;
// -------------------- -------
SolidBrush brushRed = new System.Drawing.SolidBrush(Color.FromArgb( 255 0 0 ));
SolidBrush brushWhite = new System.Drawing.SolidBrush(Color.FromArgb( 255 255 255 ));
Font font1 = new System.Drawing.Font( Tahoma,200F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,(( byte )( 0 )));
float xx,yy = 10 ;
Graphics g;
矩形矩形;
// -------------------- ------------
public Form1()
{
InitializeComponent() ;
}

void f1( Object x,EventArgs e)
{
g.DrawString( Jan-2-2015,font1 ,brushWhite,xx,yy);
xx = xx + 5 ;
g.DrawString( Jan-2-2015,font1,brushRed,xx,日);
if (( int )xx > = panel1.Width)xx = -panel1.Width;

/ * rect = new Rectangle((int)xx,(int)yy,imageFile .Width,imageFile.Height);
g.FillRectangle(brushWhite,rect);
xx = xx + 1;
po =新的PointF(xx,10.0F);
g.DrawImage(imageFile,po);
if((int)xx> = pictureBox1.Width)xx = -imageFile.Width;
* /

}

private void Timer1_Click( object sender,EventArgs e)
{
tm.Interval = 20 < /跨度>;
tm.Enabled = true ;
tm.Tick + = new EventHandler(f1);
tm.Start();
}

private void Stop_Timer1( object sender,EventArgs e)
{
tm.Stop();
g.Dispose();
}

private void FormLoad( object sender,EventArgs e)
{
g = panel1.CreateGraphics();
xx = -panel1.Width;
rect = new 矩形( 1 1 ,panel1.Width,panel1.Height);
}

解决方案

首先,在Panel.Paint事件中进行绘制并使用提供的Graphics而不是每次都创建自己的图形上下文。然后,你在Timer Tick事件处理程序中使面板无效。



这不会解决你的问题,但它会使你的代码变得更好并使其更好地工作.. 。

然后设置 Panel.DoubleBuffered属性 [ ^ ]为true,闪烁应该消失。


Hellow
i am trying to anamate text its size is 200 ,it works but i notice a flicker in the letters.I tryed by drawstring using 2 diffrent colors
(white to erase string then Red to draw the string ),i also did the similar thing using a image jpg but no diffrence
any suggestion or if you know any other method

Timer tm = new Timer();
Image imageFile;
PointF po;
Graphics g;
//---------------------------
SolidBrush brushRed = new System.Drawing.SolidBrush(Color.FromArgb(255, 0, 0));
SolidBrush brushWhite = new System.Drawing.SolidBrush(Color.FromArgb(255, 255, 255));
Font font1 = new System.Drawing.Font("Tahoma", 200F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
float xx , yy = 10;
Graphics g;
Rectangle rect;
//--------------------------------
public Form1()
{
    InitializeComponent();
}

void f1(Object x,EventArgs e)
{
    g.DrawString("Jan-2-2015", font1, brushWhite, xx, yy);
    xx = xx + 5;
    g.DrawString("Jan-2-2015", font1, brushRed, xx, yy);
    if ((int)xx >= panel1.Width) xx = -panel1.Width;

    /*rect = new Rectangle((int)xx, (int)yy, imageFile.Width, imageFile.Height);
    g.FillRectangle(brushWhite, rect);
    xx = xx + 1;
    po = new PointF(xx, 10.0F);
    g.DrawImage(imageFile, po);
    if ((int)xx >= pictureBox1.Width) xx = -imageFile.Width;
    */
}

private void Timer1_Click(object sender, EventArgs e)
{
    tm.Interval = 20;
    tm.Enabled = true;
    tm.Tick += new EventHandler(f1);
    tm.Start();
}

private void Stop_Timer1(object sender, EventArgs e)
{
    tm.Stop();
    g.Dispose();
}

private void FormLoad(object sender, EventArgs e)
{
   g=panel1.CreateGraphics();
   xx = -panel1.Width;
   rect = new Rectangle(1, 1, panel1.Width, panel1.Height);
}

解决方案

First off, do the drawing in the Panel.Paint event and use the supplied Graphics object instead of creating your own Graphics context each time. You then Invalidate the panel in the Timer Tick event handler.

That won't cure your problem, but it will neaten up your code and make it work better...
Then set the Panel.DoubleBuffered property[^] to true and the flicker should be gone.


这篇关于在漫游文本中不必要的闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆