I need to draw a lot of 2D graphics in the window. If I keep refreshing, it will lead to slow efficiency. I have learned about the drawing method with dirty rectangles. When using dirty rectangles for drawing, do I need to merge the old graphics with the refreshed graphics, and then move or zoom in and out together.
I tried multi buffering to draw these 2D graphics, but when the window zooms in and out, it still needs to be redrawn, which consumes a lot of time to run. I also tried using Bitmap to zoom in and out, but this will cause pixel distortion when zooming in. So I'd like to know if there is some solutions for this problem. It will be appreciated that if someone could give me some clue. Thanks for advance.
private void PicDisplayCtr_Paint(object sender, PaintEventArgs e)
{
m_PicDisplayControl.m_GlobalGraphics = e.Graphics;
m_PicDisplayControl.drwPaint();
if (m_PicDisplayControl.bMBtnDown)
{
m_PicDisplayControl.drwPoint(true);
}
else
{
m_PicDisplayControl.drwPoint();
}
m_PicDisplayControl.drwScale();
}
public void drwPoint(bool bRet = false)
{
if (!bRet)
{
double d1;
d1 = myView.PPU * myView.ZoomLevel;
BmpTabele = new Bitmap((int)(m_dInterRight * d1 + 1), (int)(m_dInterTop * d1) + 1);
GraphicsTabele = Graphics.FromImage(BmpTabele);
PointF pfFirstPos = new PointF(0, 0);
PointF pfSecondPos = new PointF(0, 0);
Rectangle rect = new Rectangle();
rect.X = (int)(m_dInterLeft * d1);
rect.Y = (int)(m_dInterBottom * d1);
rect.Width = (int)((m_dInterRight * d1) - (m_dInterLeft * d1));
rect.Height = (int)((m_dInterTop * d1) - (m_dInterBottom * d1));
m_InterRect = rect;
GraphicsTabele.DrawRectangle(Pens.White, rect);
for (int i = 0; i < m_DrawPointF.m_DrawPos.Count; i++)
{
pfFirstPos = new PointF(m_DrawPointF.m_DrawPos[i].X - m_PosWidth / 2, m_DrawPointF.m_DrawPos[i].Y - m_PosLength / 2);
pfSecondPos = new PointF(m_DrawPointF.m_DrawPos[i].X + m_PosWidth / 2, m_DrawPointF.m_DrawPos[i].Y + m_PosLength / 2);
rect = new Rectangle();
rect.X = (int)(pfFirstPos.X * d1);
rect.Y = (int)((m_dInterTop - m_dInterBottom - m_DrawPointF.m_DrawPos[i].Y - m_PosLength / 2) * d1);
rect.Width = (int)((pfSecondPos.X * d1) - (pfFirstPos.X * d1));
rect.Height = (int)((pfSecondPos.Y * d1) - (pfFirstPos.Y * d1));
GraphicsTabele.FillRectangle(m_DrawPointF.brushe, rect);
GraphicsTabele.DrawRectangle(m_DrawPointF.pen, rect);
}
m_FirstDrwPos.X = (int)Func_U2PX(m_dInterLeft);
m_FirstDrwPos.Y = (int)Func_U2PY(m_dInterTop);
int nWidth = (int)(Func_U2PX(m_dInterRight) - Func_U2PX(m_dInterLeft));
int nHeight = (int)(Func_U2PX(m_dInterTop) - Func_U2PX(m_dInterBottom));
//m_GlobalGraphics.DrawImage(BmpTabele, m_FirstDrwPos.X, m_FirstDrwPos.Y, nWidth, nHeight);
m_GlobalGraphics.DrawImage(BmpTabele, m_FirstDrwPos.X, m_FirstDrwPos.Y);
m_dMBtnDownX = m_MDownFirstPos.X;
m_dMBtnDownY = m_MDownFirstPos.Y;
}
else
{
m_GlobalGraphics.DrawImage(BmpTabele, (float)(m_MDownFirstPos.X - m_dMBtnDownX+ m_FirstDrwPos.X), (float)(m_MDownFirstPos.Y - m_dMBtnDownY+ m_FirstDrwPos.Y));
}
}