/************************************************/
/*★ Graphics を取得して画像を分割 前田 稔 ★*/
/************************************************/
using System;
using System.Drawing;
using System.Windows.Forms;
class MyForm : Form
{
Bitmap girl;
Bitmap[] sp_girl = new Bitmap[7];
Graphics graphics;
int SP_NO;
public MyForm()
{
try
{ girl = new Bitmap("c:\\data\\test\\girl.gif"); }
catch
{ MessageBox.Show("画像ファイルが読めません!");
return ;
}
for(int i=0; i<7; i++)
{ sp_girl[i] = new Bitmap(128,216);
graphics = Graphics.FromImage(sp_girl[i]);
graphics.DrawImage(girl,new Rectangle(0,0,128,216),
new Rectangle(128*i,0,128,216),GraphicsUnit.Pixel);
}
Paint += new PaintEventHandler(MyHandler);
MouseDown += new MouseEventHandler(OnMyMouseDown);
SP_NO = 0;
}
private void MyHandler(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawImage(sp_girl[SP_NO], 60, 20);
}
private void OnMyMouseDown(object sender, MouseEventArgs e)
{
SP_NO= (SP_NO+1)%7;
Invalidate();
}
}
class form01
{ public static void Main()
{ MyForm mf = new MyForm();
Application.Run(mf);
}
}
|