图像到文本Progam

时间:2016-04-15 12:21:18

标签: c#

我只有一个按钮应该做的事情,但当我按下它没有任何反应?我知道这只是一个小错误,我现在看不到可能有人可以帮助我吗?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;

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

    private void Form1_Load(object sender, EventArgs e)
    {

    }
    private string ConvertImage(Bitmap sBit)
    {
        MemoryStream imageStream = new MemoryStream();
        sBit.Save(imageStream, ImageFormat.Jpeg);

        return Convert.ToBase64String(imageStream.ToArray());
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Bitmap sBit = new Bitmap(@"C:\12.jpg");
        string imageString = ConvertImage(sBit);

        StreamWriter sw = new StreamWriter(@"C:\12.text", false);
        sw.Write(imageString);
        sw.Close();
    }
  }
}

1 个答案:

答案 0 :(得分:2)

您是否将按钮绑定到点击事件?

enter image description here

InitializeComponent方法应包含以下行:

this.button1.Click + = new System.EventHandler(this.button1_Click);