본문 바로가기
삽질기초/SW

c# 전역 비트맵. 다시그리기.

by @가을바람 2009. 11. 4.
이래하면 되는건가.
에레이.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;

namespace ImageByBitmap
{
public partial class Form1 : Form
{
Bitmap bmp;
Graphics bmpgraphics;
Point p1 = new Point();
Point p2 = new Point();

public Form1()
{
InitializeComponent();
base.SetStyle(ControlStyles.DoubleBuffer, true);
base.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
base.SetStyle(ControlStyles.ResizeRedraw, true);

bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
bmpgraphics = Graphics.FromImage(bmp);

bmpgraphics.TranslateTransform(200, 200);
DrawAxis();

}

private void Form1_Load(object sender, EventArgs e)
{
}

private void btClear_Click(object sender, EventArgs e)
{
SolidBrush sBrush = new SolidBrush(pictureBox1.BackColor);
bmpgraphics.FillRectangle(sBrush, -200,-200,400,400);
sBrush.Dispose();




DrawAxis();
}

private void btdraw_Click(object sender, EventArgs e)
{
Pen pen = new Pen(Color.Blue);
p1.X = 100; p1.Y = 0;
p2.X = 100; p2.Y = 100;
bmpgraphics.DrawLine(pen, p1, p2);       // Graphics의 선을 그리는 함수
pen.Dispose();


p1.X = 0; p1.Y = 0;
p2.X = 100; p2.Y = 100;
DrawPoint(p1, p2, Color.Red);


}

private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawImage(bmp, 0, 0);
pictureBox1.Invalidate();
}
private void DrawAxis() //그냥 그리기.
{

Pen pen = new Pen(Color.Blue);


p1.X = -400; p1.Y = 0;
p2.X = 400; p2.Y = 0;
bmpgraphics.DrawLine(pen, p1, p2);       // Graphics의 선을 그리는 함수
p1.Y = -400; p1.X = 0;
p2.Y = 400; p2.X = 0;
bmpgraphics.DrawLine(pen, p1, p2);       // Graphics의 선을 그리는 함수

p1.X = -200; p1.Y = 2;
p2.X = -200; p2.Y = -2;
for (int i = 0; i <= 40; i++)
{
p1.X += 10;
p2.X += 10;
bmpgraphics.DrawLine(pen, p1, p2);
}
p1.Y = -200; p1.X = 2;
p2.Y = -200; p2.X = -2;
for (int i = 0; i <= 40; i++)
{
p1.Y += 10;
p2.Y += 10;
bmpgraphics.DrawLine(pen, p1, p2);
}


pen.Dispose();
}
private void DrawPoint(Point L1, Point L2, Color color)
{

Pen pen = new Pen(color);
L1.Y = -L1.Y;
L2.Y = -L2.Y;
bmpgraphics.DrawLine(pen, L1, L2);       // Graphics의 선을 그리는 함수
pen.Dispose();
}
}
}

'삽질기초 > SW' 카테고리의 다른 글

Visual Assist X 1727  (0) 2010.02.23
c언어 기초 행렬 연산  (0) 2010.01.31
C# 기본 그래픽  (0) 2009.11.04
CString LPSTR WCHAR*  (0) 2009.08.30
.NET Framework의 개요  (0) 2009.08.30