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
|
Bitmap Bmp = new Bitmap(185,50);
Graphics ObjGraphics = Graphics.FromImage(Bmp);
// Choix aléatoire de la couleur de fond
// (limité à 200 pour une couleur foncée)
Random NBRand = new Random(DateTime.Now.Millisecond);
int R, V, B;
R = NBRand.Next(0, 200);
V = NBRand.Next(0, 200);
B = NBRand.Next(0, 200);
// Coloration du fond de l'image
SolidBrush MyBrush = new SolidBrush(Color.FromArgb(R, V, B));
ObjGraphics.FillRectangle(MyBrush, 0, 0, 185, 50);
// création Font pour Texte
Font MyFont = new Font("Arial",25,FontStyle.Regular);
// Stylo pour ecrire
Pen MyPen = new Pen(Color.Red);
PointF MyCoord = new PointF(5.0F, 5.0F);
// Liste des caractères utilisés
String[] AlphaNum ={"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K",
"L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
"W", "X", "Y", "Z", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
String Txt = "";
int i = 0;
int NewNb;
while (i < 10)
{
NewNb = NBRand.Next(0,34);
Txt += AlphaNum[NewNb].ToString();
i++;
}
ObjGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
ObjGraphics.DrawString(Txt.ToString(), MyFont, MyBrush, MyCoord);
Response.ContentType = "image/jpeg";
Bmp.Save(Response.OutputStream, ImageFormat.Jpeg); |
Partager