2016年6月2日 星期四

C#-examination-3

題目要求:

  • 讀圖。
  • show 出圖之大小,包含 width and height。
  • show 出中間點 width/2 and height/2 之 RGB 值。
##ReadMore##

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AForge.Imaging;
using AForge.Imaging.Filters;
using AForge.Imaging.Formats;

namespace examination_3
{
    public partial class exam3 : Form
    {

        Bitmap img;
        Color colorPixel;

        public exam3()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
             OpenFileDialog readImg = new OpenFileDialog();
             if (readImg.ShowDialog() == DialogResult.OK)
             {
                 img = new Bitmap(readImg.FileName);
                 pictureBox1.Image = img;

                 textBox1.Text = img.Width.ToString();
                 textBox2.Text = img.Height.ToString();

                 colorPixel = img.GetPixel(img.Width / 2, img.Height / 2);
                 textBox3.Text = colorPixel.R.ToString();
                 textBox4.Text = colorPixel.G.ToString();
                 textBox5.Text = colorPixel.B.ToString();

             }
        }
    }
}

沒有留言:

張貼留言