1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Pixel
{
public partial class Form1 : Form
{
int x = 0;
int c = 0; //variable que je déclare ici
Bitmap [] tmp = new Bitmap[2500];
public Form1()
{
InitializeComponent();
for (int b = 0; b < 2500; b++)
{
tmp[b] = new Bitmap(10, 10);
}
this.panel1.Paint += delegate(object sender, PaintEventArgs e)
{
for (int i = 0; i < 40; i++)
{
for (int j = 0; j < 50; j++)
{
e.Graphics.DrawImageUnscaled(tmp[c], 0 + (j * 10), 0 + (i * 10));
c++; //j'ai besoin d'y accéder ici
}
}
};
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.D1)
{
for (int i = 0; i < 10; i++)
for (int j = 0; j < 10; j++)
{
tmp[x].SetPixel(i, j, Color.Black);
}
x++;
((Form)sender).Refresh();
}
else if (e.KeyCode == Keys.D0)
{
for (int i = 0; i < 10; i++)
for (int j = 0; j < 10; j++)
{
tmp[x].SetPixel(i, j, Color.White);
}
x++;
((Form)sender).Refresh();
}
else if (e.KeyCode == Keys.Delete && x != 0)
{
x--;
for (int i = 0; i < 10; i++)
for (int j = 0; j < 10; j++)
{
tmp[x].SetPixel(i, j, Color.Transparent);
}
((Form)sender).Refresh();
}
else if (e.KeyCode == Keys.S && x != 0)
{
Bitmap bmp = new Bitmap(panel1.Width, panel1.Height);
panel1.DrawToBitmap(bmp, new Rectangle(0, 0, panel1.Width, panel1.Height));
bmp.Save("capture.bmp", ImageFormat.Bmp);
bmp.Dispose();
}
else if (e.KeyCode == Keys.C && x != 0)
{
//putNumbers();
}
}
//private void panel1_paint(object sender, PaintEventArgs e)
//{
// int c = 0;
// for(int i=0;i<40;i++)
// {
// for (int j = 0; j < 50; j++)
// {
// e.Graphics.DrawImageUnscaled(tmp[c], 0 + (j * 10), 0 + (i * 10));
// c++;
// }
// }
//}
//static public Bitmap BitmapFromBitmapData(byte[] BitmapData)
//{
// MemoryStream ms = new MemoryStream(BitmapData);
// return (new Bitmap(ms));
//}
//static public byte[] BitmapDataFromBitmap(Bitmap objBitmap, ImageFormat imageFormat)
//{
// MemoryStream ms = new MemoryStream();
// objBitmap.Save(ms, imageFormat);
// return (ms.GetBuffer());
//}
}
} |
Partager