mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-27 22:42:38 +01:00
Improved left/right cropping for export images
git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@940 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
ac806aa685
commit
44b651eb5c
@ -474,7 +474,10 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
g.DrawPath(new Pen(parameter.BorderColor, parameter.BorderWidth), path);
|
||||
g.FillPath(new SolidBrush(parameter.SubtitleColor), path);
|
||||
g.Dispose();
|
||||
return bmp;
|
||||
NikseBitmap nbmp = new NikseBitmap(bmp);
|
||||
nbmp.CropTransparentSides(5);
|
||||
return nbmp.GetBitmap();
|
||||
//return bmp;
|
||||
}
|
||||
|
||||
private static string RemoveSubStationAlphaFormatting(string s)
|
||||
|
@ -357,6 +357,66 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void CropTransparentSides(int maximumCropping)
|
||||
{
|
||||
int leftStart = 0;
|
||||
bool done = false;
|
||||
for (int x = 0; x < Width; x++)
|
||||
{
|
||||
for (int y = 0; y < Height; y++)
|
||||
{
|
||||
Color c = GetPixel(x, y);
|
||||
if (c.A != 0)
|
||||
{
|
||||
done = true;
|
||||
leftStart = x;
|
||||
leftStart -= maximumCropping;
|
||||
if (leftStart < 0)
|
||||
leftStart = 0;
|
||||
break;
|
||||
}
|
||||
if (done)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int rightEnd = Width-1;
|
||||
done = false;
|
||||
for (int x = Width - 1; x >= 0; x--)
|
||||
{
|
||||
for (int y = 0; y < Height; y++)
|
||||
{
|
||||
Color c = GetPixel(x, y);
|
||||
if (c.A != 0)
|
||||
{
|
||||
done = true;
|
||||
rightEnd = x;
|
||||
rightEnd += maximumCropping;
|
||||
if (rightEnd >= Width)
|
||||
rightEnd = Width-1;
|
||||
break;
|
||||
}
|
||||
if (done)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (leftStart < 2 && rightEnd >= Width - 3)
|
||||
return;
|
||||
|
||||
int newWidth = rightEnd - leftStart + 1;
|
||||
var newBitmapData = new byte[newWidth * Height * 4];
|
||||
int index = 0;
|
||||
for (int y = 0; y < Height; y++)
|
||||
{
|
||||
int pixelAddress = (leftStart * 4) + (y * 4 * Width);
|
||||
Buffer.BlockCopy(_bitmapData, pixelAddress, newBitmapData, index, 4 * newWidth);
|
||||
index += 4 * newWidth;
|
||||
}
|
||||
Width = newWidth;
|
||||
_bitmapData = newBitmapData;
|
||||
}
|
||||
|
||||
public void Fill(Color color)
|
||||
{
|
||||
byte[] buffer = new byte[4];
|
||||
|
Loading…
Reference in New Issue
Block a user