public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
generateImage();
}
int value = 0;
private void generateImage()
{
Random random = new Random (); // get a random instance
value = random.Next(10000, 99999); // get a random value between any range
var image = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height); // Get a bitmap
var font = new Font("TimesNewRoman", 25, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel); // Get a font
var graphics = Graphics.FromImage(image); // Get a graphics with the bitmap image
graphics.DrawString(value.ToString (), font, Brushes.Red, new PointF(0, 0)); // Add the value in the graphics
Pen p = new Pen(Brushes.Orange, 2.0f); // get pen width
graphics.DrawLine(p, new PointF(0,this.pictureBox1 .Height), new Point(this.pictureBox1.Width,0)); // draw a diagonal line
graphics.DrawLine(p, new PointF(0,0), new Point(this.pictureBox1.Width , this.pictureBox1.Height)); // draw another diagonal line
p.Dispose(); // dispose the pen to avoid memory leak
graphics.SmoothingMode = SmoothingMode.AntiAlias; // Smoothing the pixel
graphics.TextRenderingHint = TextRenderingHint.AntiAlias; // Smoothing the text rendering because stem width may differ
this.pictureBox1.Image = image; // load the image in the picturebox
}
private void button2_Click(object sender, EventArgs e)
{
this.generateImage();
}
private void button1_Click(object sender, EventArgs e)
{
if (this.textBox1.Text == value.ToString())
{
MessageBox.Show("Inserted value is correct");
}
else
{
MessageBox.Show("the value you have entered is wrong");
textBox1.Text = String.Empty;
}
}
}
Abhijeet SinghPosted Mar 31, 2014, 6:49 AM
http://stackoverflow.com/questions/18584427/capture-image-from-camera-automatically-after-sometime-via-coding
http://www.codeproject.com/Articles/6123/Image-Capture