关于c#的WinForm窗体里关于图片的平滑滚动效果的实现
青羽飞扬 2009-09-13 07:14:29 关于c#的WinForm窗体里关于图片的平滑滚动效果的实现,内容如题
补充的事是,在图片象素比较大的时候实现。
我现在是在窗体的Paint事件里直接写的,
代码如下
Graphics g = e.Graphics;
Rectangle clientRectangle = e.ClipRectangle;
g.Clear(System.Drawing.Color.White);
Region regClip = g.Clip;
g.Clip = new Region(clientRectangle);
int Y = (int)((this.ClientSize.Height - imageHandler.Current_Bitmap.Height*ZoomFactor) / 2);
int X = (int)((this.ClientSize.Width - imageHandler.Current_Bitmap.Width * ZoomFactor) / 2);
if (Y < 0)
{
Y = 0;
}
if (X < 0)
{
X = 0;
}
g.TranslateTransform(X, Y);
// 设置插值模式
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bicubic;
// 设置平滑模式
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
//g.Clip = new Region(new Rectangle(PublicCode.ChangeLayerStyle(this.Height,this.Width,imageHandler.Current_Bitmap),new Size(Convert.ToInt32(imageHandler.Current_Bitmap.Width * ZoomFactor), Convert.ToInt32(imageHandler.Current_Bitmap.Height * ZoomFactor))));
g.DrawImage(imageHandler.Current_Bitmap, new Rectangle(this.AutoScrollPosition.X, this.AutoScrollPosition.Y, Convert.ToInt32(imageHandler.Current_Bitmap.Width * ZoomFactor), Convert.ToInt32(imageHandler.Current_Bitmap.Height * ZoomFactor)));
这样的显示的图片如果比较大的话,2-3MB的时候,滚动的时候还是出现轻微的闪烁与延迟
希望哪位答案能解决的方法,
可以联系QQ,276321742;24小时在线