Monday 13 January 2014

c# RGB magnifier



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            x = new Bitmap(pictureBox1.Image);
        }

        private Bitmap x;

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            textBox2.Text = "(" + e.X + "," + e.Y + ")";

            var pixelcolor = x.GetPixel(e.X, e.Y);
            textBox1.Text = pixelcolor.ToString();
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            textBox2.Text = "(" + e.X + "," + e.Y + ")";
            textBox3.Text = "(" + (Cursor.Position.X - pictureBox2.Size.Width / 4) + "," + (Cursor.Position.Y - pictureBox2.Size.Height / 4) + ")";

            var pixelcolor = x.GetPixel(e.X, e.Y);
            textBox1.Text = pixelcolor.ToString();

            Bitmap z = new Bitmap(pictureBox2.Size.Width / 2, pictureBox2.Size.Height / 2);
            Graphics g = Graphics.FromImage(z);
            Size y = new Size(pictureBox2.Size.Width / 2, pictureBox2.Size.Height / 2);
            g.CopyFromScreen(new Point(Cursor.Position.X - pictureBox2.Size.Width / 4, Cursor.Position.Y - pictureBox2.Size.Height / 4), Point.Empty, y);
            pictureBox2.Image = (Image)z;
        }
    }
}

No comments:

Post a Comment