LAB20
การโหลดภาพเพื่อแสดงลง Form
namespace teynakopha
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Bitmap bmp = new Bitmap("d:\\ปี 3 2556\\tey1.jpg");
this.SetClientSizeCore(bmp.Width + 20, bmp.Height + 20);
e.Graphics.DrawImage(bmp, 10, 10);
}
}
}
การ Zoom
in
namespace teynakopha
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Bitmap bmp = new Bitmap("d:\\ปี 3 2556\\tey1.jpg");
Rectangle destrect = new Rectangle(10, 10, bmp.Width / 2, bmp.Height / 2);
Rectangle srcrect = new Rectangle(0, 0, bmp.Width, bmp.Height);
this.SetClientSizeCore(destrect.Width + 20, destrect.Height +
20);
e.Graphics.DrawImage(bmp, destrect,
srcrect, GraphicsUnit.Pixel);
}
}
}
การ
Zoom out
namespace teynakopha
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Bitmap bmp = new Bitmap("d:\\ปี 3 2556\\tey1.jpg");
Rectangle destrect = new Rectangle(10, 10, bmp.Width , bmp.Height );
Rectangle srcrect = new Rectangle(0, 0, bmp.Width/2, bmp.Height/2);
this.SetClientSizeCore(destrect.Width + 20, destrect.Height +
20);
e.Graphics.DrawImage(bmp, destrect,
srcrect, GraphicsUnit.Pixel);
}
}
}
การพลิกและการหมุนภาพ
namespace teynakopha
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Bitmap bmp = new Bitmap("d:\\ปี 3 2556\\tey1.jpg");
this.SetClientSizeCore(bmp.Width, bmp.Height);
Rectangle topleft = new Rectangle(0, 0, bmp.Width / 2, bmp.Height / 2);
Rectangle topright = new Rectangle(bmp.Width / 2, 0, bmp.Width / 2, bmp.Height / 2);
Rectangle bottomleft = new Rectangle(0, bmp.Height / 2, bmp.Width / 2, bmp.Height / 2);
Rectangle bottomright = new Rectangle(bmp.Width / 2, bmp.Height / 2, bmp.Width / 2, bmp.Height
/ 2);
bmp.RotateFlip(RotateFlipType.RotateNoneFlipNone);
e.Graphics.DrawImage(bmp, topleft);
bmp.RotateFlip(RotateFlipType.RotateNoneFlipX);
e.Graphics.DrawImage(bmp,
topright);
bmp.RotateFlip(RotateFlipType.Rotate180FlipNone);
e.Graphics.DrawImage(bmp,
bottomleft);
bmp.RotateFlip(RotateFlipType.Rotate180FlipY);
e.Graphics.DrawImage(bmp,
bottomright);
}
}
}
การเขียนข้อความลงในภาพ
namespace teynakopha
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Bitmap bmp = new Bitmap("d:\\ปี 3 2556\\tey1.jpg");
this.SetClientSizeCore(bmp.Width, bmp.Height);
Rectangle destrect = new Rectangle(0, 0, bmp.Width, bmp.Height);
Brush myBrush = new SolidBrush(Color.Coral);
e.Graphics.DrawImage(bmp,
destrect);
e.Graphics.DrawString("TEYNAKOPHA",
new Font("Verdana", 70, FontStyle.Regular), myBrush, 0, 0);
}
}
}