本文整理汇总了C#中Nikse.SubtitleEdit.Logic.NikseBitmap.GetAlpha方法的典型用法代码示例。如果您正苦于以下问题:C# NikseBitmap.GetAlpha方法的具体用法?C# NikseBitmap.GetAlpha怎么用?C# NikseBitmap.GetAlpha使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nikse.SubtitleEdit.Logic.NikseBitmap
的用法示例。
在下文中一共展示了NikseBitmap.GetAlpha方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CropTopAndBottom
public static NikseBitmap CropTopAndBottom(NikseBitmap bmp, out int topCropping)
{
int startTop = 0;
int maxTop = bmp.Height - 2;
if (maxTop > bmp.Height)
{
maxTop = bmp.Height;
}
for (int y = 0; y < maxTop; y++)
{
bool allTransparent = true;
for (int x = 1; x < bmp.Width - 1; x++)
{
int a = bmp.GetAlpha(x, y);
if (a != 0)
{
allTransparent = false;
break;
}
}
if (!allTransparent)
{
break;
}
startTop++;
}
//if (startTop > 9)
//startTop -= 5; // if top space > 9, then allways leave blank 5 pixels on top (so . is not confused with ').
topCropping = startTop;
int height = bmp.Height;
bool bottomCroppingDone = false;
for (int y = bmp.Height - 1; y > 3; y--)
{
for (int x = 1; x < bmp.Width - 1; x++)
{
int a = bmp.GetAlpha(x, y);
if (a != 0)
{
bottomCroppingDone = true;
break;
}
}
height = y;
if (bottomCroppingDone)
{
break;
}
}
return bmp.CopyRectangle(new Rectangle(0, startTop, bmp.Width, height - startTop + 1));
}
示例2: CropTopAndBottom
public static NikseBitmap CropTopAndBottom(NikseBitmap bmp, out int topCropping, int maxDifferentPixelsOnLine)
{
int startTop = 0;
int maxTop = bmp.Height - 2;
if (maxTop > bmp.Height)
maxTop = bmp.Height;
for (int y = 0; y < maxTop; y++)
{
int difference = 0;
bool allTransparent = true;
for (int x = 1; x < bmp.Width - 1; x++)
{
int a = bmp.GetAlpha(x, y);
if (a != 0)
{
difference++;
if (difference >= maxDifferentPixelsOnLine)
{
allTransparent = false;
break;
}
}
}
if (!allTransparent)
break;
startTop++;
}
if (startTop > 9)
startTop -= 5; // if top space > 9, then allways leave blank 5 pixels on top (so . is not confused with ').
topCropping = startTop;
for (int y = bmp.Height - 1; y > 3; y--)
{
int difference = 0;
bool allTransparent = true;
for (int x = 1; x < bmp.Width - 1; x++)
{
int a = bmp.GetAlpha(x, y);
if (a != 0)
{
difference++;
if (difference >= maxDifferentPixelsOnLine)
{
allTransparent = false;
break;
}
}
}
if (allTransparent == false)
return bmp.CopyRectangle(new Rectangle(0, startTop, bmp.Width - 1, y - startTop + 1));
}
return bmp;
}
示例3: IsBitmapsAlike
internal static unsafe int IsBitmapsAlike(NikseBitmap bmp1, Ocr.Binary.BinaryOcrBitmap bmp2)
{
int different = 0;
int maxDiff = bmp1.Width * bmp1.Height / 5;
for (int x = 1; x < bmp1.Width; x++)
{
for (int y = 1; y < bmp1.Height; y++)
{
if (bmp1.GetAlpha(x, y) < 100 && bmp2.GetPixel(x, y) > 0)
different++;
}
if (different > maxDiff)
return different + 10;
}
return different;
}
示例4: IsVerticalLineTransparetNew
private static List<Point> IsVerticalLineTransparetNew(NikseBitmap bmp, int x, out bool right, out bool clean)
{
right = false;
bool left = false;
clean = true;
var points = new List<Point>();
int y = 0;
while (y < bmp.Height)
{
if (bmp.GetAlpha(x, y) > 100)
{
clean = false;
if (x == 0)
return null;
if (x < bmp.Width - 1 && y < bmp.Height - 1 && bmp.GetAlpha(x + 1, y) == 0 && bmp.GetAlpha(x + 1, y + 1) == 0)
{
//if pixels to the left - move right?
if (bmp.GetAlpha(x - 1, y) > 0)
{
x++; //(requires search for min/max x in points
right = true;
}
else if (x > 0 && bmp.GetAlpha(x - 1, y) == 0)
{
x--; //(requires search for min/max x in points
left = true;
}
else
{
return null;
}
}
else if (x < bmp.Width - 1 && y == bmp.Height - 1 && bmp.GetAlpha(x + 1, y) == 0 && bmp.GetAlpha(x + 1, y - 1) == 0)
{
//if pixels to the left - move right?
if (bmp.GetAlpha(x - 1, y) > 0)
{
x++; //(requires search for min/max x in points
right = true;
}
else
{
return null;
}
right = true;
}
else if (bmp.GetAlpha(x - 1, y) == 0)
{
x--;
left = true;
}
else if (y > 5 && bmp.GetAlpha(x - 1, y - 1) == 0)
{
x--;
y--;
left = true;
while (points.Count > 0 && points[points.Count - 1].Y > y)
points.RemoveAt(points.Count - 1);
}
else if (y > 5 && bmp.GetAlpha(x - 1, y - 2) == 0)
{
x--;
y -= 2;
left = true;
while (points.Count > 0 && points[points.Count - 1].Y > y)
points.RemoveAt(points.Count - 1);
}
else
{
return null;
}
if (left && right)
return null;
}
else
{
points.Add(new Point(x, y));
y++;
}
}
return points;
}
示例5: IsVerticalLineTransparentAlphaOnly
private static bool IsVerticalLineTransparentAlphaOnly(NikseBitmap bmp, ref int y, int x)
{
bool allTransparent = true;
for (y = 0; y < bmp.Height - 1; y++)
{
int a = bmp.GetAlpha(x, y);
if (a == 0) // still dark color...
{
}
else
{
allTransparent = false;
break;
}
}
return allTransparent;
}
示例6: RemoveBlackBarRight
private static void RemoveBlackBarRight(NikseBitmap bmp)
{
int xRemoveBlackBar = bmp.Width - 1;
for (int yRemoveBlackBar = 0; yRemoveBlackBar < bmp.Height; yRemoveBlackBar++)
{
byte[] c = bmp.GetPixelColors(xRemoveBlackBar, yRemoveBlackBar);
if (c[0] == 0 || IsColorClose(c[0], c[1], c[2], c[3], Color.Black, 280))
{
if (bmp.GetAlpha(xRemoveBlackBar - 1, yRemoveBlackBar) == 0)
bmp.SetPixel(xRemoveBlackBar, yRemoveBlackBar, Color.Transparent);
}
}
}
示例7: SplitVertical
public static List<ImageSplitterItem> SplitVertical(NikseBitmap bmp, int minLineHeight)
{ // split into lines
int startY = 0;
int size = 0;
var parts = new List<ImageSplitterItem>();
for (int y = 0; y < bmp.Height; y++)
{
bool allTransparent = true;
for (int x = 0; x < bmp.Width; x++)
{
int a = bmp.GetAlpha(x, y);
if (a != 0)
{
allTransparent = false;
break;
}
}
if (allTransparent)
{
if (size > 2 && size <= minLineHeight)
{
size++; // at least 'lineMinHeight' pixels, like top of 'i'
}
else
{
if (size > 2)
{
NikseBitmap part = bmp.CopyRectangle(new Rectangle(0, startY, bmp.Width, size + 1));
// part.Save("c:\\line_0_to_width.bmp");
parts.Add(new ImageSplitterItem(0, startY, part));
// bmp.Save("c:\\original.bmp");
}
size = 0;
startY = y;
}
}
else
{
size++;
}
}
if (size > 2)
{
if (size == bmp.Height)
{
if (size > 100)
return SplitVerticalTransparentOrBlack(bmp);
else
parts.Add(new ImageSplitterItem(0, startY, bmp));
}
else
{
parts.Add(new ImageSplitterItem(0, startY, bmp.CopyRectangle(new Rectangle(0, startY, bmp.Width, size + 1))));
}
}
return parts;
}
示例8: IsBitmapsAlike
internal static int IsBitmapsAlike(Ocr.Binary.BinaryOcrBitmap bmp1, NikseBitmap bmp2)
{
int different = 0;
int maxDiff = bmp1.Width * bmp1.Height / 5;
for (int x = 1; x < bmp1.Width; x++)
{
for (int y = 1; y < bmp1.Height; y++)
{
//if (!IsColorClose(bmp1.GetPixel(x, y), bmp2.GetPixel(x, y), 20))
if (bmp1.GetPixel(x, y) > 0 && bmp2.GetAlpha(x, y) < 100)
different++;
}
if (different > maxDiff)
return different + 10;
}
return different;
}
示例9: RemoveBlackBarRight
private static void RemoveBlackBarRight(NikseBitmap bmp)
{
int xRemoveBlackBar = bmp.Width - 1;
for (int yRemoveBlackBar = 0; yRemoveBlackBar < bmp.Height; yRemoveBlackBar++)
{
byte[] colors = bmp.GetPixelColors(xRemoveBlackBar, yRemoveBlackBar);
if (colors[0] != 0 && !IsColorClose(colors[0], colors[1], colors[2], colors[3], Color.Black, 280))
{
continue;
}
if (bmp.GetAlpha(xRemoveBlackBar - 1, yRemoveBlackBar) == 0)
{
bmp.SetPixel(xRemoveBlackBar, yRemoveBlackBar, Color.Transparent);
}
}
}
示例10: IsVerticalLineTransparentAlphaOnly
private static bool IsVerticalLineTransparentAlphaOnly(NikseBitmap bmp, ref int y, int x)
{
bool allTransparent = true;
for (y = 0; y < bmp.Height - 1; y++)
{
int a = bmp.GetAlpha(x, y);
if (a == 0)
{
continue;
}
allTransparent = false;
break;
}
return allTransparent;
}