Current location - Recipe Complete Network - Health preserving recipes - Write pretzel noise, gaussian noise, median filter, gaussian low pass, high pass program for image in C#
Write pretzel noise, gaussian noise, median filter, gaussian low pass, high pass program for image in C#
Bitmap image = new Bitmap(50,22);

Graphics g = Graphics.FromImage(image);

try

{

//Generate a random generator

Random random = new Random();

//clear the background color of the image

g.Clear(Color.White);

//draw the background noise line of the image

for (int i = 0; i < 25; i++)

{

int x1 = random.Next(image.Width);

int x2 = random.Next(image.Width);

int y1 = random.Next(image.Height);

int y2 = random.Next( image.Height);

g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);

}

Font font = new Font("Arial", 12, (FontStyle.Bold | FontStyle. FontStyle.Italic));

LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color. Color.Crimson, 1.2f, true);

g.DrawString(checkCode, font, brush, 0, 0);

//Draw the foreground noise point of the image

for (int i = 0; i < 100; i++)

{

int x = random.Next(image.Width);

int y = random.Next(image.Height);

image.SetPixel(x, y, Color.FromArgb(random.Next()));

}

// Draw the border line of the image

g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);

System.IO. MemoryStream ms = new System.IO.MemoryStream();

image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);

Response. ClearContent();

Response.ContentType = "image/Gif";

Response.BinaryWrite(ms.ToArray());

}

finally

{

g.Dispose();

image.Dispose();

}

Hope this helps