Exemple #1
0
        public void TestMethodBinOcrSaveLoad()
        {
            string tempFileName = System.IO.Path.GetTempFileName();
            var db = new BinaryOcrDb(tempFileName);
            var nbmp = new NikseBitmap(2, 2);
            nbmp.SetPixel(0, 0, Color.Transparent);
            nbmp.SetPixel(1, 0, Color.Transparent);
            nbmp.SetPixel(1, 0, Color.Transparent);
            nbmp.SetPixel(1, 1, Color.White);

            var bob = new BinaryOcrBitmap(nbmp);
            bob.Text = "Debug";
            db.Add(bob);

            nbmp.SetPixel(0, 0, Color.White);
            var bob2 = new BinaryOcrBitmap(nbmp);
            bob2.X = 2;
            bob2.Y = 4;
            bob2.Text = "tt";
            bob2.Italic = true;
            bob2.ExpandCount = 2;
            bob2.ExpandedList = new System.Collections.Generic.List<BinaryOcrBitmap>();
            bob2.ExpandedList.Add(bob2);
            db.Add(bob2);
            db.Save();

            db = new BinaryOcrDb(tempFileName, true);
            Assert.IsTrue(db.CompareImages.Count == 1);
            Assert.IsTrue(db.CompareImagesExpanded.Count == 1);

            Assert.IsTrue(bob.Width == db.CompareImages[0].Width);
            Assert.IsTrue(bob.Height == db.CompareImages[0].Height);
            Assert.IsTrue(bob.NumberOfColoredPixels == db.CompareImages[0].NumberOfColoredPixels);
            Assert.IsTrue(bob.Hash == db.CompareImages[0].Hash);
            Assert.IsTrue(bob.Italic == db.CompareImages[0].Italic);
            Assert.IsTrue(bob.ExpandCount == db.CompareImages[0].ExpandCount);
            Assert.IsTrue(bob.Text == db.CompareImages[0].Text);

            Assert.IsTrue(bob2.Width == db.CompareImagesExpanded[0].Width);
            Assert.IsTrue(bob2.Height == db.CompareImagesExpanded[0].Height);
            Assert.IsTrue(bob2.NumberOfColoredPixels == db.CompareImagesExpanded[0].NumberOfColoredPixels);
            Assert.IsTrue(bob2.Hash == db.CompareImagesExpanded[0].Hash);
            Assert.IsTrue(bob2.Italic == db.CompareImagesExpanded[0].Italic);
            Assert.IsTrue(bob2.ExpandCount == db.CompareImagesExpanded[0].ExpandCount);
            Assert.IsTrue(bob2.Text == db.CompareImagesExpanded[0].Text);
            Assert.IsTrue(bob2.X == db.CompareImagesExpanded[0].X);
            Assert.IsTrue(bob2.Y == db.CompareImagesExpanded[0].Y);

            try
            {
                System.IO.File.Delete(tempFileName);
            }
            catch
            {
            }
        }
Exemple #2
0
 private void ButtonNewCharacterDatabaseClick(object sender, EventArgs e)
 {
     var newFolder = new VobSubOcrNewFolder(comboBoxOcrMethod.SelectedIndex == 1);
     if (newFolder.ShowDialog(this) == DialogResult.OK)
     {
         if (comboBoxOcrMethod.SelectedIndex == 4)
         {
             try
             {
                 string fileName = Path.Combine(Configuration.OcrFolder, newFolder.FolderName + ".db");
                 if (System.IO.File.Exists(fileName))
                 {
                     MessageBox.Show("OCR db already exists!");
                     return;
                 }
                 comboBoxCharacterDatabase.Items.Add(newFolder.FolderName);
                 comboBoxCharacterDatabase.SelectedIndex = comboBoxCharacterDatabase.Items.Count - 1;
                 _binaryOcrDb = new BinaryOcrDb(fileName);
                 _binaryOcrDb.Save();
             }
             catch (Exception exception)
             {
                 MessageBox.Show(exception.Message);
             }
         }
         else
         {
             _vobSubOcrSettings.LastImageCompareFolder = newFolder.FolderName;
             LoadImageCompareCharacterDatabaseList();
             LoadImageCompareBitmaps();
         }
     }
 }