2017-06-27 14 views
0

私が働いている小売業者向けのプログラムを作ろうとしています。人々が車を配達するとき、男はLenovo miixで損害賠償の写真を撮らなければなりません。テキストボックスから名前を取得したフォルダに画像を保存するbuttomを作成します

私がこれまでに作ったプログラムは、十分にスマートではありません。 これは、ナンバープレートをボックスに書き込んだ後、ボックスからテキストを含むフォルダを作成するようになります。

次に、カメラを起動して写真を撮って保存し、手動でフォルダを見つけてファイル名を付ける必要があります。

pic of program 私はカメラと写真を撮るために別のものを開始するには、ちょうど2ボタンで賢くものを、それを作ることができる方法はありますし、それは自動的にナンバーという名前のフォルダにそれを保存し、ファイルが命名1,2,3,4など.jpg?

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

     private FilterInfoCollection webcam; 
     private VideoCaptureDevice cam; 

     private void Form1_Load(object sender, EventArgs e) 
     { 
      webcam = new FilterInfoCollection(FilterCategory.VideoInputDevice); 
      foreach(FilterInfo VideoCaptureDevice in webcam) 
      { 
       comboBox1.Items.Add(VideoCaptureDevice.Name); 
      } 
      comboBox1.SelectedIndex = 1; 
     } 

     private void button1_Click(object sender, EventArgs e) 
     { 
      cam = new VideoCaptureDevice(webcam[comboBox1.SelectedIndex].MonikerString); 
      cam.NewFrame += new NewFrameEventHandler(Cam_NewFrame); 
      cam.Start(); 
     } 

     private void Cam_NewFrame(object sender, NewFrameEventArgs eventArgs) 
     { 
      Bitmap bit = (Bitmap)eventArgs.Frame.Clone(); 
      pictureBox1.Image = bit; 
     } 

     private void button3_Click(object sender, EventArgs e) 
     { 
      if (cam.IsRunning) 
      { 
       cam.Stop(); 
      } 
     } 

     private void button2_Click(object sender, EventArgs e) 
     { 
      saveFileDialog1.InitialDirectory = @"C:\tmp\"; 
      if (saveFileDialog1.ShowDialog() == DialogResult.OK) 
      { 
       pictureBox1.Image.Save(saveFileDialog1.FileName); 
      } 
     } 

     private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) 
     { 

     } 

     private void pictureBox1_Click(object sender, EventArgs e) 
     { 

     } 

     private void label1_Click(object sender, EventArgs e) 
     { 

     } 

     private void saveFileDialog1_FileOk(object sender, CancelEventArgs e) 
     { 

     } 

     private void nummerplade_TextChanged(object sender, EventArgs e) 
     { 

     } 

     private void button4_Click(object sender, EventArgs e) 
     { 
      Directory.CreateDirectory(@"c:\tmp\" + nummerplade.Text); 
     } 
    } 
} 
+2

regプレートをボックスに書き込むと、そのテキストをファイル名として使用できません。 – BugFinder

+0

あなたのbutton4_Clickイベントはあなたのためのディレクトリ構造を構築しています。これを修正して、アプリケーションにローカル変数としてパスを保存するようにしてください。 – uk2k05

+0

あなたの画像に自動的に番号を付けるには、画像を増やして画像に割り当てます。ナンバープレートを変更するためにアプリを閉じることで、数字が上がるほど画像が多くなります。 – uk2k05

答えて

0

何かこのような:これは私のこれまでのコードである

代わりのSaveFileDialogを使用して、あなただけのこのようなナンバープレート値に基づいてファイルパスを作成することができます。

var filePath = System.IO.Path.Combine(@"c:\tmp", nummerplade.Text, fileNumber + ".jpeg"); 

fileNumber VaRは、ファイルの数は、フォルダ+ 1

に出回っています

var fileNumber = Directory.GetFiles(...).Length + 1

また、あなたはそれを行うための多くの方法がありますが、増分の名前をしたいと述べ
0
string numberPlate = "21323412"; 
string path = @"C:\tmp\"; 

Directory.CreateDirectory(path + numberPlate); //to create folder 
string dirpath = path + numberPlate; //to get name of fodler we created 

、個人的に私はそうのようなファイルの大規模なハッシュされた名前を好む:

//generate GUID and convert to string. 
string filename = Guid.NewGuid().ToString(); 

//to save picturebox image in folder and use ImageFormat.Your desired format 
pictureBox1.Image.Save(dirpath + @"\"+filename+".jpeg", ImageFormat.Jpeg); 

しかし、あなた場合を最終的には次のようになりますGUIDで

// you get last name in the folder: 

//it gets last filename in folder but with path 
var lastFilePath = directory.GetFiles().OrderByDescending(f => f.LastWriteTime).First(); 

//we remove path from filename and convert it to int. 
int lastIndex = Int32.Parse(Path.GetFileNameWithoutExtension(lastFilePath)); 

//then we increment it by 1 
int newName = lastIndex + 1; 

//and save it 
pictureBox1.Image.Save(dirpath + @"\"+filename+".jpeg", ImageFormat.Jpeg); //to save picturebox image in folder 

:インクリメンタル名前に固執したい

string numberPlate = "21323412"; 
    string path = @"C:\tmp\"; 

    private void button2_Click(object sender, EventArgs e) 
    { 
     Directory.CreateDirectory(path + numberPlate); //to create folder 
     string dirpath = path + numberPlate; //to get name of fodler we created 
     string filename = Guid.NewGuid().ToString(); 
     pictureBox1.Image.Save(dirpath + @"\"+filename+".jpeg", ImageFormat.Jpeg); //to save picturebox image in folder 

    } 
+0

[リンク](http://oi67.tinypic.com/9ppcat.jpg)私はこのエラーを受け取ります – Peter

+0

@Peter私は私の答えにいくつかの変更を加えました。 – Nick

+0

私を助けてくれてありがとう!:) .. エラーが発生する:名前 'ImageFormat'がカレンダーコンテキストに存在しない[link](http://oi65.tinypic.com/1676pvc.jpg) – Peter

関連する問題