2016-04-15 9 views
-2

私は、そのことをすると思われるボタンは1つしかありませんが、私はそれを押しても何も起こりません。私はちょうど私がちょうど誰かが私を助けることができるかもしれないことがわかりません、それはちょっとした間違いです知っていますか?Image to Text Progam

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(); 
    } 
    } 
} 
+4

何も起こらないことは不可能です。コードが実行されるか、例外がスローされます。イベントハンドラをバインドしましたか? – CodeCaster

+1

"button1"コントロール:Clickイベントをハンドラにバインドしましたか? –

+0

'InitializeComponent()'定義に行きます(それをクリックしてF12キーを押します)。この行があるかどうかを調べてください: 'this.button1.Click + = new System.EventHandler(this.button1_Click);'。あなたがしない場合は、それを置く:) – Nino

答えて

2

ボタンをクリックイベントにバインドしましたか?

enter image description here

InitializeComponentメソッドは、この行含める必要があります

this.button1.Click + =新しいSystem.EventHandler(this.button1_Click)を、

+0

downvoteの理由はありますか? – sereschkin

+0

ありがとうございます。私はそれを完全に忘れています。イメージをテキストに変換せず、ランダムな文字を含むテキストファイルを作成するだけです。 – Unreal28

+0

ファイル内でどのような文字が期待されていますか? – sereschkin