Ejemplo n.º 1
0
 private void button5_Click(object sender, EventArgs e)
 {
     ImageHandle1.DoBinaryzation(SrcBmp, DestBmp, Convert.ToInt16(textBox1.Text));
     DestPicture.Image = DestBmp;
     DrawHistGram(HistBmp, HistGram);
     SrcHist.Invalidate();
 }
Ejemplo n.º 2
0
        private void 打开图像ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.RestoreDirectory = true;                              //假设用户在搜索文件的过程中更改了目录,那么,如果对话框会将当前目录还原为初始值,则值为 true;反之,值为 false。 默认值为 false。
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                SrcBmp.Dispose();
                Bitmap Temp = (Bitmap)Bitmap.FromFile(openFileDialog.FileName);
                if (IsGrayBitmap(Temp) == true)
                {
                    SrcBmp = Temp;
                }
                else
                {
                    SrcBmp = ConvertToGrayBitmap(Temp);
                    Temp.Dispose();                                             //释放图像所占用的资源
                }
                SrcPicture.Image = SrcBmp;
                DestBmp.Dispose();
                DestBmp = CreateGrayBitmap(SrcBmp.Width, SrcBmp.Height);
                ImageHandle1.GetHistGram(SrcBmp, HistGram);
                DrawHistGram(HistBmp, HistGram);
                SrcHist.Invalidate();
                comboBox_ImageSize.Text = SrcBmp.Height.ToString() + 'x' + SrcBmp.Width.ToString();
                richTextBox1.Text       = openFileDialog.ToString();
            }
        }
Ejemplo n.º 3
0
 private void button6_Click(object sender, EventArgs e)
 {
     ImageHandle1.DoBinaryzation(SrcBmp, DestBmp, Threshold.GetOSTUThreshold(HistGram));
     DestPicture.Image = DestBmp;
     textBox1.Text     = Threshold.GetOSTUThreshold(HistGram).ToString();
     DrawHistGram(HistBmp, HistGram);
     SrcHist.Invalidate();
 }
Ejemplo n.º 4
0
 private void button3_Click(object sender, EventArgs e)
 {
     ImageHandle1.DoBinaryzation(SrcBmp, DestBmp, 110);
     DestPicture.Image = DestBmp;
     textBox1.Text     = 110.ToString();
     DrawHistGram(HistBmp, HistGram);
     SrcHist.Invalidate();
 }
Ejemplo n.º 5
0
        void ReceiveImage()
        {
            int i = 0;

            i = LastReceiveCount;
            while (i < ReceiveDataCount - ImageHeight * ImageWidth - 10)
            {
                if (listRecvRecordData[i] == 0xFE && listRecvRecordData[i + 1] == 0xEF)
                {
                    if (listRecvRecordData[i + 2 + ImageHeight * ImageWidth] == 0xEF && listRecvRecordData[i + 3 + ImageHeight * ImageWidth] == 0xFE)
                    {
                        i++;
                        i++;
                        ImageReceiveCount++;
                        TextBox_ReceiveCount.Text = ImageReceiveCount.ToString();
                        SrcBmp.Dispose();
                        SrcBmp = CreateGrayBitmap(ImageHeight, ImageWidth);
                        BitmapData SrcData   = SrcBmp.LockBits(new Rectangle(0, 0, ImageHeight, ImageWidth), ImageLockMode.ReadWrite, SrcBmp.PixelFormat);
                        int        SrcStride = SrcData.Stride;
                        byte *     SrcP;
                        for (int Y = 0; Y < ImageWidth; Y++)
                        {
                            SrcP = (byte *)SrcData.Scan0 + Y * SrcStride;                // 必须在某个地方开启unsafe功能,其实C#中的unsafe很safe,搞的好吓人。
                            for (int X = 0; X < ImageHeight; SrcP++, X++)
                            {
                                *SrcP = listRecvRecordData[i];
                                i++;
                            }
                        }
                        SrcBmp.UnlockBits(SrcData);
                        ImageHandle1.GetHistGram(SrcBmp, HistGram);
                        DrawHistGram(HistBmp, HistGram);
                        SrcHist.Invalidate();

                        SrcPicture.Image = SrcBmp;
                        if (radioButton1.Checked)
                        {
                            SaveImage("imaging", "AutoPicture");
                        }
                        i++;
                        i++;
                        LastReceiveCount = i;
                    }
                }
                i++;
            }
        }
Ejemplo n.º 6
0
        void InitImage()
        {
            Bitmap Temp = (Bitmap)Bitmap.FromFile(System.IO.Directory.GetCurrentDirectory() + "\\Picture\\Image" + "0" + ".bmp");

            if (IsGrayBitmap(Temp) == true)
            {
                SrcBmp = Temp;
            }
            else
            {
                SrcBmp = ConvertToGrayBitmap(Temp);
                Temp.Dispose();                                             //释放图像所占用的资源
            }
            DestBmp = CreateGrayBitmap(SrcBmp.Width, SrcBmp.Height);
            comboBox_ImageSize.Text = SrcBmp.Height.ToString() + 'x' + SrcBmp.Width.ToString();
            SrcPicture.Image        = SrcBmp;
            HistBmp       = CreateGrayBitmap(256, 100);
            SmoothHistBmp = CreateGrayBitmap(256, 100);
            SrcHist.Image = HistBmp;
            ImageHandle1.GetHistGram(SrcBmp, HistGram);

            DrawHistGram(HistBmp, HistGram);
            SrcHist.Invalidate();
        }