当前位置: 首页>>代码示例>>C#>>正文


C# NikseBitmap.ReplaceNonWhiteWithTransparent方法代码示例

本文整理汇总了C#中Nikse.SubtitleEdit.Logic.NikseBitmap.ReplaceNonWhiteWithTransparent方法的典型用法代码示例。如果您正苦于以下问题:C# NikseBitmap.ReplaceNonWhiteWithTransparent方法的具体用法?C# NikseBitmap.ReplaceNonWhiteWithTransparent怎么用?C# NikseBitmap.ReplaceNonWhiteWithTransparent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Nikse.SubtitleEdit.Logic.NikseBitmap的用法示例。


在下文中一共展示了NikseBitmap.ReplaceNonWhiteWithTransparent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Initialize

        internal void Initialize(Bitmap bitmap, int pixelsIsSpace, bool rightToLeft, NOcrDb nOcrDb, VobSubOcr vobSubOcr)
        {
            _bitmap = bitmap;
            var nbmp = new NikseBitmap(bitmap);
            nbmp.ReplaceNonWhiteWithTransparent();
            bitmap = nbmp.GetBitmap();
            _bitmap2 = bitmap;
            _nocrChars = nOcrDb.OcrCharacters;
            _matchList = new List<VobSubOcr.CompareMatch>();
            _vobSubOcr = vobSubOcr;

            int minLineHeight = 6;
            _imageList = NikseBitmapImageSplitter.SplitBitmapToLettersNew(nbmp, pixelsIsSpace, rightToLeft, Configuration.Settings.VobSubOcr.TopToBottom, minLineHeight);
            // _imageList = NikseBitmapImageSplitter.SplitBitmapToLetters(nbmp, pixelsIsSpace, rightToLeft, Configuration.Settings.VobSubOcr.TopToBottom);

            int index = 0;
            while (index < _imageList.Count)
            {
                ImageSplitterItem item = _imageList[index];
                if (item.NikseBitmap == null)
                {
                    listBoxInspectItems.Items.Add(item.SpecialCharacter);
                    _matchList.Add(null);
                }
                else
                {
                    nbmp = item.NikseBitmap;
                    nbmp.ReplaceNonWhiteWithTransparent();
                    item.Y += nbmp.CropTopTransparent(0);
                    nbmp.CropTransparentSidesAndBottom(0, true);
                    nbmp.ReplaceTransparentWith(Color.Black);

                    //get nocr matches
                    Nikse.SubtitleEdit.Forms.VobSubOcr.CompareMatch match = vobSubOcr.GetNOcrCompareMatchNew(item, nbmp, nOcrDb, false, false);
                    if (match == null)
                    {
                        listBoxInspectItems.Items.Add("?");
                        _matchList.Add(null);
                    }
                    else
                    {
                        listBoxInspectItems.Items.Add(match.Text);
                        _matchList.Add(match);
                    }
                }
                index++;
            }

        }
开发者ID:athikan,项目名称:subtitleedit,代码行数:49,代码来源:VobSubNOcrCharacterInspect.cs

示例2: NocrFastCheck

        public string NocrFastCheck(Bitmap bitmap)
        {
            var nbmpInput = new NikseBitmap(bitmap);
            nbmpInput.ReplaceNonWhiteWithTransparent();

            var matches = new List<CompareMatch>();
            List<ImageSplitterItem> list = NikseBitmapImageSplitter.SplitBitmapToLetters(nbmpInput, (int)numericUpDownNumberOfPixelsIsSpaceNOCR.Value, checkBoxRightToLeft.Checked, Configuration.Settings.VobSubOcr.TopToBottom);

            foreach (ImageSplitterItem item in list)
            {
                if (item.NikseBitmap != null)
                {
                    item.NikseBitmap.ReplaceTransparentWith(Color.Black);
                }
            }
            int index = 0;
            var expandSelectionList = new List<ImageSplitterItem>();
            while (index < list.Count)
            {
                ImageSplitterItem item = list[index];
                if (item.NikseBitmap == null)
                {
                    matches.Add(new CompareMatch(item.SpecialCharacter, false, 0, null));
                }
                else
                {
                    CompareMatch match = null;

                    var nbmp = item.NikseBitmap;
                    int index2 = 0;
                    int topMargin = item.Y - item.ParentY;
                    foreach (NOcrChar oc in _nOcrDb.OcrCharacters)
                    {
                        if (Math.Abs(oc.Width - nbmp.Width) < 3 && Math.Abs(oc.Height - nbmp.Height) < 4 && Math.Abs(oc.MarginTop - topMargin) < 4)
                        { // only very accurate matches

                            bool ok = true;
                            index2 = 0;
                            while (index2 < oc.LinesForeground.Count && ok)
                            {
                                NOcrPoint op = oc.LinesForeground[index2];
                                foreach (Point point in op.ScaledGetPoints(oc, nbmp.Width, nbmp.Height))
                                {
                                    if (point.X >= 0 && point.Y >= 0 && point.X < nbmp.Width && point.Y < nbmp.Height)
                                    {
                                        Color c = nbmp.GetPixel(point.X, point.Y);
                                        if (c.A > 150 && c.R + c.G + c.B > NocrMinColor)
                                        {
                                        }
                                        else
                                        {
                                            Point p = new Point(point.X - 1, point.Y);
                                            if (p.X < 0)
                                                p.X = 1;
                                            c = nbmp.GetPixel(p.X, p.Y);
                                            if (nbmp.Width > 20 && c.A > 150 && c.R + c.G + c.B > NocrMinColor)
                                            {
                                            }
                                            else
                                            {
                                                ok = false;
                                                break;
                                            }
                                        }
                                    }
                                }
                                index2++;
                            }
                            index2 = 0;
                            while (index2 < oc.LinesBackground.Count && ok)
                            {
                                NOcrPoint op = oc.LinesBackground[index2];
                                foreach (Point point in op.ScaledGetPoints(oc, nbmp.Width, nbmp.Height))
                                {
                                    if (point.X >= 0 && point.Y >= 0 && point.X < nbmp.Width && point.Y < nbmp.Height)
                                    {
                                        Color c = nbmp.GetPixel(point.X, point.Y);
                                        if (c.A > 150 && c.R + c.G + c.B > NocrMinColor)
                                        {
                                            Point p = new Point(point.X, point.Y);
                                            if (oc.Width > 19 && point.X > 0)
                                                p.X = p.X - 1;
                                            c = nbmp.GetPixel(p.X, p.Y);
                                            if (c.A > 150 && c.R + c.G + c.B > NocrMinColor)
                                            {
                                                ok = false;
                                                break;
                                            }
                                        }
                                    }
                                }
                                index2++;
                            }
                            if (ok)
                                match = new CompareMatch(oc.Text, oc.Italic, 0, null);
                        }
                    }

                    if (match == null)
                    {
//.........这里部分代码省略.........
开发者ID:Tarhan,项目名称:subtitleedit,代码行数:101,代码来源:VobSubOcr.cs

示例3: NOcrThreadDoWork

        static void NOcrThreadDoWork(object sender, DoWorkEventArgs e)
        {
            var p = (NOcrThreadParameter)e.Argument;
            e.Result = p;
            var nbmpInput = new NikseBitmap(p.Picture);
            nbmpInput.ReplaceNonWhiteWithTransparent();

            var matches = new List<CompareMatch>();
            int minLineHeight = p.NOcrLastLowercaseHeight;
            if (minLineHeight < 10)
                minLineHeight = 22;
            int maxLineHeight = p.NOcrLastUppercaseHeight;
            if (maxLineHeight < 10)
                minLineHeight = 80;

            List<ImageSplitterItem> list = NikseBitmapImageSplitter.SplitBitmapToLettersNew(nbmpInput, p.NumberOfPixelsIsSpace, p.RightToLeft, Configuration.Settings.VobSubOcr.TopToBottom, minLineHeight);
            foreach (ImageSplitterItem item in list)
            {
                if (item.NikseBitmap != null)
                {
                    var nbmp = item.NikseBitmap;
            //                    nbmp.ReplaceNonWhiteWithTransparent();
                    item.Y += nbmp.CropTopTransparent(0);
                    nbmp.CropTransparentSidesAndBottom(0, true);
                    nbmp.ReplaceTransparentWith(Color.Black);
                }
            }
            int index = 0;
            while (index < list.Count)
            {
                ImageSplitterItem item = list[index];
                if (item.NikseBitmap == null)
                {
                    matches.Add(new CompareMatch(item.SpecialCharacter, false, 0, null));
                }
                else
                {
                    CompareMatch match = GetNOcrCompareMatch(item, nbmpInput, p);
                    if (match == null)
                    {
                        p.Result = string.Empty;
                        return;
                    }
                    else // found image match
                    {
                        matches.Add(new CompareMatch(match.Text, match.Italic, 0, null));
                        if (match.ExpandCount > 0)
                            index += match.ExpandCount - 1;
                    }
                }
                index++;
            }
            p.Result = GetStringWithItalicTags(matches);
        }
开发者ID:Tarhan,项目名称:subtitleedit,代码行数:54,代码来源:VobSubOcr.cs

示例4: OcrViaNOCR

        private string OcrViaNOCR(Bitmap bitmap, int listViewIndex)
        {
            if (_ocrFixEngine == null)
                comboBoxDictionaries_SelectedIndexChanged(null, null);

            string line = string.Empty;
            if (_nocrThreadResults != null)
                line = _nocrThreadResults[listViewIndex];
            if (string.IsNullOrEmpty(line))
            {
                var nbmpInput = new NikseBitmap(bitmap);
                nbmpInput.ReplaceNonWhiteWithTransparent();

                var matches = new List<CompareMatch>();
                List<ImageSplitterItem> list = NikseBitmapImageSplitter.SplitBitmapToLetters(nbmpInput, (int)numericUpDownNumberOfPixelsIsSpaceNOCR.Value, checkBoxRightToLeft.Checked, Configuration.Settings.VobSubOcr.TopToBottom);

                foreach (ImageSplitterItem item in list)
                {
                    if (item.NikseBitmap != null)
                    {
                        item.NikseBitmap.ReplaceNonWhiteWithTransparent();
                        item.Y += item.NikseBitmap.CropTopTransparent(0);
                        item.NikseBitmap.CropTransparentSidesAndBottom(0, true);
                        item.NikseBitmap.ReplaceTransparentWith(Color.Black);
                    }
                }
                int index = 0;
                bool expandSelection = false;
                bool shrinkSelection = false;
                var expandSelectionList = new List<ImageSplitterItem>();
                while (index < list.Count)
                {
                    ImageSplitterItem item = list[index];
                    if (expandSelection || shrinkSelection)
                    {
                        expandSelection = false;
                        if (shrinkSelection && index > 0)
                        {
                            shrinkSelection = false;
                        }
                        else if (index + 1 < list.Count && list[index + 1].NikseBitmap != null) // only allow expand to EndOfLine or space
                        {

                            index++;
                            expandSelectionList.Add(list[index]);
                        }
                        item = GetExpandedSelection(nbmpInput, expandSelectionList, checkBoxRightToLeft.Checked);
                        if (item.NikseBitmap != null)
                        {
                            item.NikseBitmap.ReplaceNonWhiteWithTransparent();
                            item.Y += item.NikseBitmap.CropTopTransparent(0);
                            item.NikseBitmap.CropTransparentSidesAndBottom(0, true);
                            item.NikseBitmap.ReplaceTransparentWith(Color.Black);
                        }

                        _vobSubOcrNOcrCharacter.Initialize(bitmap, item, _manualOcrDialogPosition, _italicCheckedLast, expandSelectionList.Count > 1, null, _lastAdditions, this);
                        DialogResult result = _vobSubOcrNOcrCharacter.ShowDialog(this);
                        _manualOcrDialogPosition = _vobSubOcrNOcrCharacter.FormPosition;
                        if (result == DialogResult.OK && _vobSubOcrNOcrCharacter.ShrinkSelection)
                        {
                            shrinkSelection = true;
                            index--;
                            if (expandSelectionList.Count > 0)
                                expandSelectionList.RemoveAt(expandSelectionList.Count - 1);
                        }
                        else if (result == DialogResult.OK && _vobSubOcrNOcrCharacter.ExpandSelection)
                        {
                            expandSelection = true;
                        }
                        else if (result == DialogResult.OK)
                        {
                            var c = _vobSubOcrNOcrCharacter.NOcrChar;
                            if (expandSelectionList.Count > 1)
                                c.ExpandCount = expandSelectionList.Count;
                            _nocrChars.Add(c);
                            SaveNOcrWithCurrentLanguage();
                            string text = _vobSubOcrNOcrCharacter.NOcrChar.Text;
                            string name = SaveCompareItem(item.NikseBitmap, text, _vobSubOcrNOcrCharacter.IsItalic, expandSelectionList.Count);
                            var addition = new ImageCompareAddition(name, text, item.NikseBitmap, _vobSubOcrNOcrCharacter.IsItalic, listViewIndex);
                            _lastAdditions.Add(addition);
                            matches.Add(new CompareMatch(text, _vobSubOcrNOcrCharacter.IsItalic, expandSelectionList.Count, null));
                            expandSelectionList = new List<ImageSplitterItem>();
                        }
                        else if (result == DialogResult.Abort)
                        {
                            _abort = true;
                        }
                        else
                        {
                            matches.Add(new CompareMatch("*", false, 0, null));
                        }
                        _italicCheckedLast = _vobSubOcrNOcrCharacter.IsItalic;

                    }
                    else if (item.NikseBitmap == null)
                    {
                        matches.Add(new CompareMatch(item.SpecialCharacter, false, 0, null));
                    }
                    else
                    {
//.........这里部分代码省略.........
开发者ID:rebawest,项目名称:subtitleedit,代码行数:101,代码来源:VobSubOcr.cs

示例5: NocrThreadDoItalicWork

        static string NocrThreadDoItalicWork(NOcrThreadParameter p)
        {
            var unItalicedBmp = UnItalic(p.Picture, p.UnItalicFactor);
            var nbmp = new NikseBitmap(unItalicedBmp);
            nbmp.ReplaceNonWhiteWithTransparent();
            Bitmap bitmap = nbmp.GetBitmap();
            unItalicedBmp.Dispose();

            var matches = new List<CompareMatch>();
            int minLineHeight = p.NOcrLastLowercaseHeight;
            if (minLineHeight < 10)
                minLineHeight = 22;
            int maxLineHeight = p.NOcrLastUppercaseHeight;
            if (maxLineHeight < 10)
                minLineHeight = 80;

            List<ImageSplitterItem> lines = NikseBitmapImageSplitter.SplitVertical(nbmp, minLineHeight);
            List<ImageSplitterItem> list = NikseBitmapImageSplitter.SplitBitmapToLetters(lines, p.NumberOfPixelsIsSpace, p.RightToLeft, Configuration.Settings.VobSubOcr.TopToBottom);

            foreach (ImageSplitterItem item in list)
            {
                if (item.NikseBitmap != null)
                {
                    item.NikseBitmap.ReplaceNonWhiteWithTransparent();
                    item.Y += item.NikseBitmap.CropTopTransparent(0);
                    item.NikseBitmap.CropTransparentSidesAndBottom(0, true);
                    item.NikseBitmap.ReplaceTransparentWith(Color.Black);
                }
            }

            int index = 0;
            while (index < list.Count)
            {
                ImageSplitterItem item = list[index];
                if (item.NikseBitmap == null)
                {
                    matches.Add(new CompareMatch(item.SpecialCharacter, false, 0, null));
                }
                else
                {
                    bool old = p.AdvancedItalicDetection;
                    p.AdvancedItalicDetection = false;
                    CompareMatch match = GetNOcrCompareMatch(item, bitmap, p);
                    p.AdvancedItalicDetection = old;
                    if (match == null)
                    {
                       return string.Empty;
                    }
                    else // found image match
                    {
                        matches.Add(new CompareMatch(match.Text, match.Italic, 0, null));
                        if (match.ExpandCount > 0)
                            index += match.ExpandCount - 1;
                    }
                }
                index++;
            }
            return "<i>" + Utilities.RemoveHtmlTags(GetStringWithItalicTags(matches)) + "</i>";
        }
开发者ID:rebawest,项目名称:subtitleedit,代码行数:59,代码来源:VobSubOcr.cs


注:本文中的Nikse.SubtitleEdit.Logic.NikseBitmap.ReplaceNonWhiteWithTransparent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。