6. Blake Neubert 的數位畫框

namespace Q6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            pictureBox1.AllowDrop = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var img = (Bitmap)pictureBox1.Image;
            for (int x = 0; x < img.Width; x++)
                for (int y = 0; y < img.Height; y++)
                {
                    var p = img.GetPixel(x, y);

                    p = Color.FromArgb(
                        p.R % 2 == 1 ? 16 : 235,
                        p.G % 2 == 1 ? 16 : 235,
                        p.B % 2 == 1 ? 16 : 235
                        );

                    img.SetPixel(x, y, p);
                }
            pictureBox1.Image = img;
        }

        private void pictureBox1_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;
        }

        private void pictureBox1_DragDrop(object sender, DragEventArgs e)
        {
            string[] d = (string[])e.Data.GetData(DataFormats.FileDrop);
            pictureBox1.Image = Bitmap.FromFile(d[0]);
            button1.Enabled = true;
            button1.Text = "Reveal The Image Behind";
        }

        private void pictureBox1_DoubleClick(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            pictureBox1.Image = Bitmap.FromFile(openFileDialog1.FileName);
            button1.Enabled = true;
            button1.Text = "Reveal The Image Behind";
        }

        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            if (pictureBox1.Image == null) e.Graphics.DrawString("Drag or Double Click \nto Select an Image",
                new Font(FontFamily.GenericSerif, 50), Brushes.Black,
                50, pictureBox1.Height / 2);
        }
    }
}

Last updated