Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Drawing.Imaging;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using AForge.Imaging.Filters;
- using AForge.Imaging;
- using AForge;
- namespace prefinalexam
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void bTNSAVE_Click(object sender, EventArgs e)
- {
- pictureBox1.Image = PanelToBitmap(paint1);
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = "Image|*.jpg";
- sfd.FileName = "Image.jpg";
- sfd.Title = "Save picture";
- if (DialogResult.OK == sfd.ShowDialog())
- {
- pictureBox1.Image = MakeGrayscale3((Bitmap)pictureBox1.Image);
- pictureBox1.Image.Save(sfd.FileName);
- }
- }
- private System.Drawing.Image PanelToBitmap(Control paint1)
- {
- var bmp = new Bitmap(paint1.Width, paint1.Height);
- paint1.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
- return bmp;
- }
- public Bitmap MakeGrayscale3(Bitmap original)
- {
- //create a blank bitmap the same size as original
- Bitmap newBitmap = new Bitmap(original.Width, original.Height);
- //get a graphics object from the new image
- Graphics g = Graphics.FromImage(newBitmap);
- //create the grayscale ColorMatrix
- ColorMatrix colorMatrix = new ColorMatrix(
- new float[][]
- {
- new float[] {.3f, .3f, .3f, 0, 0},
- new float[] {.59f, .59f, .59f, 0, 0},
- new float[] {.11f, .11f, .11f, 0, 0},
- new float[] {0, 0, 0, 1, 0},
- new float[] {0, 0, 0, 0, 1}
- });
- //create some image attributes
- ImageAttributes attributes = new ImageAttributes();
- //set the color matrix attribute
- attributes.SetColorMatrix(colorMatrix);
- //draw the original image on the new image
- //using the grayscale color matrix
- g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height),
- 0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);
- //dispose the Graphics object
- g.Dispose();
- return newBitmap;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- SusanCornersDetector s = new SusanCornersDetector();
- List<IntPoint> c = s.ProcessImage((Bitmap)pictureBox1.Image);
- Graphics g = Graphics.FromImage(pictureBox1.Image);
- SolidBrush b = new SolidBrush(Color.Red);
- Pen p = new Pen(b);
- foreach (IntPoint k in c)
- {
- g.DrawRectangle(p, k.X - 1, k.Y - 1, 3, 3);
- }
- pictureBox1.Image = (Bitmap)pictureBox1.Image ;
- if (c.Count == 0)
- {
- MessageBox.Show("You Draw a circle");
- }
- else if (c.Count == 3)
- {
- MessageBox.Show("You Draw a triangle");
- }
- else if (c.Count == 4)
- {
- MessageBox.Show("You Draw a Square");
- }
- else
- {
- MessageBox.Show("What kind of object you draw?");
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- paint1.DrawingShapes = new PicLoaderE1.Shapes();
- paint1.Refresh();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement