diff --git a/src/Forms/VobSubOcr.cs b/src/Forms/VobSubOcr.cs index b8a28ba98..c87278498 100644 --- a/src/Forms/VobSubOcr.cs +++ b/src/Forms/VobSubOcr.cs @@ -1269,6 +1269,8 @@ namespace Nikse.SubtitleEdit.Forms nDvbBmp.CropTransparentSidesAndBottom(2, true); if (checkBoxTransportStreamGetColorAndSplit.Checked) _dvbSubColor = nDvbBmp.GetBrightestColor(); + if (checkBoxAutoTransparentBackground.Checked) + nDvbBmp.MakeBackgroundTransparent(140); //TODO: Put in UI or settings if (checkBoxTransportStreamGrayscale.Checked) nDvbBmp.GrayScale(); dvbBmp.Dispose(); diff --git a/src/Logic/NikseBitmap.cs b/src/Logic/NikseBitmap.cs index 0256fecb3..4a85e7c21 100644 --- a/src/Logic/NikseBitmap.cs +++ b/src/Logic/NikseBitmap.cs @@ -972,5 +972,23 @@ namespace Nikse.SubtitleEdit.Logic } } + + /// + /// Make pixels with some transparency completely transparent + /// + /// Min alpha value, 0=transparent, 255=fully visible + internal void MakeBackgroundTransparent(int minAlpha) + { + byte[] buffer = new byte[4]; + buffer[0] = 0; // B + buffer[1] = 0; // G + buffer[2] = 0; // R + buffer[3] = 0; // A + for (int i = 0; i < _bitmapData.Length; i += 4) + { + if (_bitmapData[i + 3] < minAlpha) + Buffer.BlockCopy(buffer, 0, _bitmapData, i, 4); + } + } } }