Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- namespace ImageEditor
- {
- public partial class BinarizeImage : Form
- {
- Bitmap image;
- public BinarizeImage(Bitmap img)
- {
- this.image = img;
- InitializeComponent();
- binaryString();
- }
- private void binaryString()
- {
- int w = image.Width;
- int h = image.Height;
- if (h > 400 || w >400)
- {
- float nh = (float)h * .75f;
- float nw = (float)w * .75f;
- Bitmap newimg = new Bitmap((int)nw, (int)nh);
- using (Graphics grx = Graphics.FromImage(newimg))
- {
- grx.DrawImage(image,0,0,nw,nh);
- }
- image = newimg;
- }
- string texto = "";
- Bitmap map = (Bitmap)image;
- string[] arr = new string[image.Height];
- //string[] arr = new string[img.Height];
- for (int i = 0; i < image.Height; i++)
- {
- for (int j = 0; j < image.Width; j++)
- {
- //richTextBox1.Font = new Font(Font.Name, 10, Font.Style);
- 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))
- {
- texto += "1";
- }
- else
- {
- texto += "0";
- }
- }
- texto = texto + "\n";
- arr[i] = texto;
- }
- //Bitmap bmap = (Bitmap)image;
- for (int i = 0; i < arr.Length; i++)
- {
- AutoScroll = true;
- AutoScrollMinSize = new Size(image.Width * 4, image.Height * 5);
- richTextBox1.Size = new Size(image.Width * 4, image.Height * 5);
- richTextBox1.Text = arr[i];
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement