開発環境 |
Microsoft Visual C# 2010 Express (SP1) |
実行環境 |
Microsoft Windows XP Home Edition (SP3) |
プロジェクトの種類 |
Windows フォーム アプリケーション |
プロジェクト名 |
DrawImg |
コモン コントロール/PictureBox
名前:pictureBox1
プロパティ:Dock:Fill、SizeMode:CenterImage
イベント
Form1.cs
using System;
using System.Drawing;
using System.Windows.Forms;
namespace DrawImg
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Bitmap img = new Bitmap(128, 128);
for (int y = 0; y < 128; y++)
{
double v = (y / (double)128 - 0.5) * 10;
for (int x = 0; x < 128; x++)
{
double u = (x / (double)128 - 0.5) * 10;
double r = Math.Sqrt(u * u + v * v);
double w = Math.Cos(r) * Math.Exp(r * r / -32);
Color c;
if (0 <= w)
{
c = Color.FromArgb((int)(w * 255), 0, 0);
}
else
{
c = Color.FromArgb(0, 0, (int)(w * -255));
}
img.SetPixel(x, y, c);
}
}
pictureBox1.Image = img;
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape) Close();
if (e.KeyCode == Keys.S && (e.Modifiers & Keys.Control) == Keys.Control)
{
string filename = @"C:\tmp\GeoMap.png";
pictureBox1.Image.Save(filename);
MessageBox.Show(filename, "DrawImg",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
最終更新:2013年01月19日 11:48