More crop for VobSub

This commit is contained in:
niksedk 2023-10-08 19:24:29 +02:00
parent 429bdb3360
commit 3ad9da7d8d
2 changed files with 29 additions and 0 deletions

View File

@ -914,6 +914,20 @@ namespace Nikse.SubtitleEdit.Core.Common
return Height - y; return Height - y;
} }
public int CalcBottomTransparent()
{
var y = Height - 1;
for (; y > 0; y--)
{
if (!IsHorizontalLineTransparent(y))
{
break;
}
}
return Height - y;
}
public int CalcLeftCropping(Color color) public int CalcLeftCropping(Color color)
{ {
var x = 0; var x = 0;
@ -968,6 +982,19 @@ namespace Nikse.SubtitleEdit.Core.Common
return true; return true;
} }
public bool IsHorizontalLineTransparent(int y)
{
for (var x = 0; x < Width; x++)
{
if (GetAlpha(x, y) > 1)
{
return false;
}
}
return true;
}
public void Fill(Color color) public void Fill(Color color)
{ {
var buffer = new byte[4]; var buffer = new byte[4];

View File

@ -2330,9 +2330,11 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
var nbmp = new NikseBitmap(bmp); var nbmp = new NikseBitmap(bmp);
var topCropped = nbmp.CropTopTransparent(0); var topCropped = nbmp.CropTopTransparent(0);
top += topCropped; top += topCropped;
var bottomCropped = nbmp.CalcBottomTransparent();
width = bmp.Width; width = bmp.Width;
height = bmp.Height; height = bmp.Height;
height -= topCropped; height -= topCropped;
height -= bottomCropped;
bmp.Dispose(); bmp.Dispose();
return; return;
} }