Advertisement
ozakisama

C# IMAPRO Binarize

Dec 11th, 2014
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace ImageEditor
  11. {
  12.     public partial class BinarizeImage : Form
  13.     {
  14.         Bitmap image;
  15.         public BinarizeImage(Bitmap img)
  16.         {
  17.             this.image = img;
  18.             InitializeComponent();
  19.             binaryString();
  20.         }
  21.  
  22.         private void binaryString()
  23.         {
  24.             int w = image.Width;
  25.             int h = image.Height;
  26.             if (h > 400 || w >400)
  27.             {
  28.                 float nh = (float)h * .75f;
  29.                 float nw = (float)w * .75f;
  30.                 Bitmap newimg = new Bitmap((int)nw, (int)nh);
  31.                 using (Graphics grx = Graphics.FromImage(newimg))
  32.                 {
  33.                     grx.DrawImage(image,0,0,nw,nh);
  34.                 }
  35.                 image = newimg;
  36.             }
  37.             string texto = "";
  38.             Bitmap map = (Bitmap)image;
  39.             string[] arr = new string[image.Height];
  40.             //string[] arr = new string[img.Height];
  41.             for (int i = 0; i < image.Height; i++)
  42.             {
  43.  
  44.                 for (int j = 0; j < image.Width; j++)
  45.                 {
  46.                     //richTextBox1.Font = new Font(Font.Name, 10, Font.Style);
  47.                     if ((map.GetPixel(j, i).A == 255 && map.GetPixel(j, i).B == 255 && map.GetPixel(j, i).G == 255 && map.GetPixel(j, i).R == 255))
  48.                     {
  49.                         texto += "1";
  50.                     }
  51.                     else
  52.                     {
  53.                         texto += "0";
  54.                     }
  55.  
  56.                 }
  57.                 texto = texto + "\n";
  58.                 arr[i] = texto;
  59.                
  60.             }
  61.             //Bitmap bmap = (Bitmap)image;
  62.             for (int i = 0; i < arr.Length; i++)
  63.             {
  64.                 AutoScroll = true;
  65.                 AutoScrollMinSize = new Size(image.Width * 4, image.Height * 5);
  66.                 richTextBox1.Size = new Size(image.Width * 4, image.Height * 5);
  67.                 richTextBox1.Text = arr[i];
  68.             }
  69.         }
  70.  
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement