Graphics.Clear winform 画图闪烁

antcy_18 2016-01-11 09:19:35
public static void FanZhuan_ZuoYou(Bitmap MyBitmap, Control picBox)
{
//以左右反转方式显示图像
try
{
int width = MyBitmap.Width; //图像宽度
int height = MyBitmap.Height; //图像高度
Graphics g = picBox.CreateGraphics();

int ia = 0;
for (int j = -height / 2; j <= height / 2; j++)
{
ia++;
g.Clear(Color.White);
int i = Convert.ToInt32(j * (Convert.ToSingle(width) / Convert.ToSingle(height)));
Rectangle DestRect = new Rectangle(width / 2 - i, 0, 2 * i, height);
Rectangle SrcRect = new Rectangle(0, 0, MyBitmap.Width, MyBitmap.Height);
g.DrawImage(MyBitmap, DestRect, SrcRect, GraphicsUnit.Pixel);
System.Threading.Thread.Sleep(10);
}
Console.WriteLine(ia);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "信息提示");
}
}public static void FanZhuan_ZuoYou(Bitmap MyBitmap, Control picBox)
{
//以左右反转方式显示图像
try
{
int width = MyBitmap.Width; //图像宽度
int height = MyBitmap.Height; //图像高度
Graphics g = picBox.CreateGraphics();

int ia = 0;
for (int j = -height / 2; j <= height / 2; j++)
{
ia++;
g.Clear(Color.White);
int i = Convert.ToInt32(j * (Convert.ToSingle(width) / Convert.ToSingle(height)));
Rectangle DestRect = new Rectangle(width / 2 - i, 0, 2 * i, height);
Rectangle SrcRect = new Rectangle(0, 0, MyBitmap.Width, MyBitmap.Height);
g.DrawImage(MyBitmap, DestRect, SrcRect, GraphicsUnit.Pixel);
System.Threading.Thread.Sleep(10);
}
Console.WriteLine(ia);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "信息提示");
}
}

从网上拿的翻转图片的函数, 发现闪烁的很厉害。

this.SetStyle(
System.Windows.Forms.ControlStyles.UserPaint |
System.Windows.Forms.ControlStyles.AllPaintingInWmPaint |
System.Windows.Forms.ControlStyles.OptimizedDoubleBuffer,
true); 这双缓冲,也用了, 没效果。
...全文
295 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
智商余额不足 2016-01-12
  • 打赏
  • 举报
回复 1

public static void FanZhuan_ZuoYou(Bitmap MyBitmap, Control picBox)
{
    //以左右反转方式显示图像 
    try
    {
        int width = MyBitmap.Width; //图像宽度 
        int height = MyBitmap.Height; //图像高度 
        Graphics g = picBox.CreateGraphics();
        BufferedGraphics bufferGfx = BufferedGraphicsManager.Current.Allocate(g, picBox.ClientRectangle);
        Graphics gfx = bufferGfx.Graphics;

        int ia = 0;
        for (int j = -height / 2; j <= height / 2; j++)
        {
            ia++;
            gfx.Clear(Color.White);
            int i = Convert.ToInt32(j * (Convert.ToSingle(width) / Convert.ToSingle(height)));
            Rectangle DestRect = new Rectangle(width / 2 - i, 0, 2 * i, height);
            Rectangle SrcRect = new Rectangle(0, 0, MyBitmap.Width, MyBitmap.Height);
            gfx.DrawImage(MyBitmap, DestRect, SrcRect, GraphicsUnit.Pixel);
            bufferGfx.Render(g);
            System.Threading.Thread.Sleep(10);
        }

        gfx.Dispose();
        bufferGfx.Dispose();

        Console.WriteLine(ia);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "信息提示");
    }
}
threenewbee 2016-01-11
  • 打赏
  • 举报
回复
画到内存中的位图对象,然后再设置给控件的bavkgroundimage属性。

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧