■■■

2016年4月3日日曜日

PictureBoxの画像を反転させる方法

PictureBoxの画像を反転させる方法
PictureBoxの幅と高さをマイナスで設定すると反転させることが可能になります。
VB.NET

Dim canvas As New Bitmap(PictureBox1.Width, PictureBox1.Height)

Dim g As Graphics = Graphics.FromImage(canvas)

Dim img As Image = Image.FromFile("test.bmp")

g.DrawImage(img, img.Width, 0, -img.Width, img.Height)

g.Dispose()

PictureBox1.Image = canvas
C#
Bitmap canvas = new Bitmap(PictureBox1.Width, PictureBox1.Height);

Graphics g = Graphics.FromImage(canvas);

Image img = Image.FromFile("test.bmp");

g.DrawImage(img, img.Width, 0, -img.Width, img.Height);

g.Dispose();

PictureBox1.Image = canvas;
■■■