本文整理汇总了C#中Nikse.SubtitleEdit.Logic.NikseBitmap.CopyRectangle方法的典型用法代码示例。如果您正苦于以下问题:C# NikseBitmap.CopyRectangle方法的具体用法?C# NikseBitmap.CopyRectangle怎么用?C# NikseBitmap.CopyRectangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nikse.SubtitleEdit.Logic.NikseBitmap
的用法示例。
在下文中一共展示了NikseBitmap.CopyRectangle方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: SplitHorizontalNew
private static IEnumerable<ImageSplitterItem> SplitHorizontalNew(ImageSplitterItem lineSplitterItem, int xOrMorePixelsMakesSpace)
{
var bmp = new NikseBitmap(lineSplitterItem.NikseBitmap);
bmp.AddTransparentLineRight();
var parts = new List<ImageSplitterItem>();
int startX = 0;
int width = 0;
int spacePixels = 0;
int subtractSpacePixels = 0;
for (int x = 0; x < bmp.Width; x++)
{
bool right;
bool clean;
List<Point> points = IsVerticalLineTransparetNew(bmp, x, out right, out clean);
if (points != null && clean)
{
spacePixels++;
}
if (right && points != null)
{
int add = FindMaxX(points, x) - x;
width = width + add;
subtractSpacePixels = add;
}
if (points == null)
{
width++;
}
else if (width > 1)
{
var bmp0 = new NikseBitmap(bmp);
// remove pixels after current;
int k = 0;
foreach (Point p in points)
{
bmp0.MakeVerticalLinePartTransparent(p.X, p.X + k, p.Y);
k++;
}
width = FindMaxX(points, x) - startX;
width++;
NikseBitmap b1 = bmp0.CopyRectangle(new Rectangle(startX, 0, width, bmp.Height));
if (spacePixels >= xOrMorePixelsMakesSpace && parts.Count > 0)
parts.Add(new ImageSplitterItem(" "));
int addY;
b1 = CropTopAndBottom(b1, out addY);
parts.Add(new ImageSplitterItem(startX + lineSplitterItem.X, addY + lineSplitterItem.Y, b1)); //y is what?
// remove pixels before next letter;
int begin = 0;
foreach (Point p in points)
{
bmp.MakeVerticalLinePartTransparent(begin, p.X, p.Y);
}
width = 1;
startX = FindMinX(points, x);
spacePixels = -subtractSpacePixels;
subtractSpacePixels = 0;
}
else
{
width = 1;
startX = FindMinX(points, x);
}
}
return parts;
}
示例4: 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;
}
示例5: SplitVerticalTransparentOrBlack
public static List<ImageSplitterItem> SplitVerticalTransparentOrBlack(NikseBitmap bmp)
{
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++)
{
Color c = bmp.GetPixel(x, y);
if (c.A > 20 && c.R + c.G + c.B > 20)
{
allTransparent = false;
break;
}
}
if (allTransparent)
{
if (size > 2 && size <= 15)
{
size++; // at least 15 pixels, like top of 'i' or top of 'È'
}
else
{
if (size > 8)
{
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)
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;
}
示例6: GetExpandedSelection
internal static ImageSplitterItem GetExpandedSelection(NikseBitmap bitmap, List<ImageSplitterItem> expandSelectionList, bool rightToLeft)
{
if (rightToLeft)
{
int minimumX = expandSelectionList[expandSelectionList.Count - 1].X - expandSelectionList[expandSelectionList.Count - 1].NikseBitmap.Width;
int maximumX = expandSelectionList[0].X;
int minimumY = expandSelectionList[0].Y;
int maximumY = expandSelectionList[0].Y + expandSelectionList[0].NikseBitmap.Height;
foreach (ImageSplitterItem item in expandSelectionList)
{
if (item.Y < minimumY)
minimumY = item.Y;
if (item.Y + item.NikseBitmap.Height > maximumY)
maximumY = item.Y + item.NikseBitmap.Height;
}
var part = bitmap.CopyRectangle(new Rectangle(minimumX, minimumY, maximumX - minimumX, maximumY - minimumY));
return new ImageSplitterItem(minimumX, minimumY, part);
}
else
{
int minimumX = expandSelectionList[0].X;
int maximumX = expandSelectionList[expandSelectionList.Count - 1].X + expandSelectionList[expandSelectionList.Count - 1].NikseBitmap.Width;
int minimumY = expandSelectionList[0].Y;
int maximumY = expandSelectionList[0].Y + expandSelectionList[0].NikseBitmap.Height;
foreach (ImageSplitterItem item in expandSelectionList)
{
if (item.Y < minimumY)
minimumY = item.Y;
if (item.Y + item.NikseBitmap.Height > maximumY)
maximumY = item.Y + item.NikseBitmap.Height;
}
var part = bitmap.CopyRectangle(new Rectangle(minimumX, minimumY, maximumX - minimumX, maximumY - minimumY));
return new ImageSplitterItem(minimumX, minimumY, part);
}
}
示例7: GetCompareMatch
private CompareMatch GetCompareMatch(ImageSplitterItem targetItem, NikseBitmap parentBitmap, out CompareMatch secondBestGuess, List<ImageSplitterItem> list, int listIndex)
{
secondBestGuess = null;
int index = 0;
int smallestDifference = 10000;
int smallestIndex = -1;
NikseBitmap target = targetItem.NikseBitmap;
if (_compareBitmaps == null)
{
secondBestGuess = null;
return null;
}
foreach (CompareItem compareItem in _compareBitmaps)
{
// check for expand match!
if (compareItem.ExpandCount > 0 && compareItem.Bitmap.Width > target.Width &&
parentBitmap.Width >= compareItem.Bitmap.Width + targetItem.X) // && parentBitmap.Height >= compareItem.Bitmap.Height + targetItem.Y) //NIXE-debug-test- what not correct?
{
int minY = targetItem.Y;
for (int j = 1; j < compareItem.ExpandCount; j++)
{
if (list != null && list.Count > listIndex + j && list[listIndex + j].Y < minY)
minY = list[listIndex + j].Y;
}
if (parentBitmap.Height >= compareItem.Bitmap.Height + minY)
{
var cutBitmap = parentBitmap.CopyRectangle(new Rectangle(targetItem.X, minY, compareItem.Bitmap.Width, compareItem.Bitmap.Height));
int dif = NikseBitmapImageSplitter.IsBitmapsAlike(compareItem.Bitmap, cutBitmap);
if (dif < smallestDifference)
{
bool allow = true;
if (Math.Abs(target.Height - compareItem.Bitmap.Height) > 5 && compareItem.Text == "\"")
allow = false;
if (allow)
{
smallestDifference = dif;
smallestIndex = index;
if (dif == 0)
break; // foreach ending
}
}
}
}
index++;
}
// Search images with minor location changes
FindBestMatch(ref index, ref smallestDifference, ref smallestIndex, target, _compareBitmaps);
if (smallestDifference * 100.0 / (target.Width * target.Height) > _vobSubOcrSettings.AllowDifferenceInPercent && target.Width < 70)
{
if (smallestDifference > 2 && target.Width > 25)
{
var cutBitmap = target.CopyRectangle(new Rectangle(4, 0, target.Width - 4, target.Height));
FindBestMatch(ref index, ref smallestDifference, ref smallestIndex, cutBitmap, _compareBitmaps);
double differencePercentage = smallestDifference * 100.0 / (target.Width * target.Height);
}
if (smallestDifference > 2 && target.Width > 12)
{
var cutBitmap = target.CopyRectangle(new Rectangle(1, 0, target.Width - 2, target.Height));
FindBestMatch(ref index, ref smallestDifference, ref smallestIndex, cutBitmap, _compareBitmaps);
}
if (smallestDifference > 2 && target.Width > 12)
{
var cutBitmap = target.CopyRectangle(new Rectangle(0, 0, target.Width - 2, target.Height));
FindBestMatch(ref index, ref smallestDifference, ref smallestIndex, cutBitmap, _compareBitmaps);
}
if (smallestDifference > 2 && target.Width > 12)
{
var cutBitmap = target.CopyRectangle(new Rectangle(1, 0, target.Width - 2, target.Height));
int topCrop = 0;
var cutBitmap2 = NikseBitmapImageSplitter.CropTopAndBottom(cutBitmap, out topCrop, 2);
if (cutBitmap2.Height != target.Height)
FindBestMatch(ref index, ref smallestDifference, ref smallestIndex, cutBitmap2, _compareBitmaps);
}
if (smallestDifference > 2 && target.Width > 15)
{
var cutBitmap = target.CopyRectangle(new Rectangle(1, 0, target.Width - 2, target.Height));
int topCrop = 0;
var cutBitmap2 = NikseBitmapImageSplitter.CropTopAndBottom(cutBitmap, out topCrop);
if (cutBitmap2.Height != target.Height)
FindBestMatch(ref index, ref smallestDifference, ref smallestIndex, cutBitmap2, _compareBitmaps);
}
if (smallestDifference > 2 && target.Width > 15)
{
var cutBitmap = target.CopyRectangle(new Rectangle(1, 0, target.Width - 2, target.Height));
int topCrop = 0;
var cutBitmap2 = NikseBitmapImageSplitter.CropTopAndBottom(cutBitmap, out topCrop);
if (cutBitmap2.Height != target.Height)
FindBestMatch(ref index, ref smallestDifference, ref smallestIndex, cutBitmap2, _compareBitmaps);
}
}
if (smallestIndex >= 0)
//.........这里部分代码省略.........
示例8: GetCompareMatchNew
private CompareMatch GetCompareMatchNew(ImageSplitterItem targetItem, NikseBitmap parentBitmap, out CompareMatch secondBestGuess, List<ImageSplitterItem> list, int listIndex)
{
double maxDiff = (double)numericUpDownMaxErrorPct.Value;
secondBestGuess = null;
int index = 0;
int smallestDifference = 10000;
int smallestIndex = -1;
NikseBitmap target = targetItem.NikseBitmap;
if (_binaryOcrDb == null)
{
secondBestGuess = null;
return null;
}
foreach (BinaryOcrBitmap compareItem in _binaryOcrDb.CompareImages)
{
// check for expand match!
if (compareItem.ExpandCount > 0 && compareItem.Width > target.Width &&
parentBitmap.Width >= compareItem.Width + targetItem.X) // && parentBitmap.Height >= compareItem.Bitmap.Height + targetItem.Y) //NIXE-debug-test- what not correct?
{
int minY = targetItem.Y;
for (int j = 1; j < compareItem.ExpandCount; j++)
{
if (list != null && list.Count > listIndex + j && list[listIndex + j].Y < minY)
minY = list[listIndex + j].Y;
}
if (parentBitmap.Height >= compareItem.Height + minY)
{
var cutBitmap = parentBitmap.CopyRectangle(new Rectangle(targetItem.X, minY, compareItem.Width, compareItem.Height));
int dif = NikseBitmapImageSplitter.IsBitmapsAlike(compareItem, cutBitmap);
if (dif < smallestDifference)
{
bool allow = true;
if (Math.Abs(target.Height - compareItem.Height) > 5 && compareItem.Text == "\"")
allow = false;
if (allow)
{
smallestDifference = dif;
smallestIndex = index;
if (dif == 0)
break; // foreach ending
}
}
}
}
index++;
}
// Search images with minor location changes
FindBestMatchNew(ref index, ref smallestDifference, ref smallestIndex, target, _binaryOcrDb);
if (maxDiff > 0)
{
if (smallestDifference * 100.0 / (target.Width * target.Height) > _vobSubOcrSettings.AllowDifferenceInPercent && target.Width < 70)
{
if (smallestDifference > 2 && target.Width > 25)
{
var cutBitmap = target.CopyRectangle(new Rectangle(4, 0, target.Width - 4, target.Height));
FindBestMatchNew(ref index, ref smallestDifference, ref smallestIndex, cutBitmap, _binaryOcrDb);
double differencePercentage = smallestDifference * 100.0 / (target.Width * target.Height);
}
if (smallestDifference > 2 && target.Width > 12)
{
var cutBitmap = target.CopyRectangle(new Rectangle(1, 0, target.Width - 2, target.Height));
FindBestMatchNew(ref index, ref smallestDifference, ref smallestIndex, cutBitmap, _binaryOcrDb);
}
if (smallestDifference > 2 && target.Width > 12)
{
var cutBitmap = target.CopyRectangle(new Rectangle(0, 0, target.Width - 2, target.Height));
FindBestMatchNew(ref index, ref smallestDifference, ref smallestIndex, cutBitmap, _binaryOcrDb);
}
if (smallestDifference > 2 && target.Width > 12)
{
var cutBitmap = target.CopyRectangle(new Rectangle(1, 0, target.Width - 2, target.Height));
int topCrop = 0;
var cutBitmap2 = NikseBitmapImageSplitter.CropTopAndBottom(cutBitmap, out topCrop, 2);
if (cutBitmap2.Height != target.Height)
FindBestMatchNew(ref index, ref smallestDifference, ref smallestIndex, cutBitmap2, _binaryOcrDb);
}
if (smallestDifference > 2 && target.Width > 15)
{
var cutBitmap = target.CopyRectangle(new Rectangle(1, 0, target.Width - 2, target.Height));
int topCrop = 0;
var cutBitmap2 = NikseBitmapImageSplitter.CropTopAndBottom(cutBitmap, out topCrop);
if (cutBitmap2.Height != target.Height)
FindBestMatchNew(ref index, ref smallestDifference, ref smallestIndex, cutBitmap2, _binaryOcrDb);
}
if (smallestDifference > 2 && target.Width > 15)
{
var cutBitmap = target.CopyRectangle(new Rectangle(1, 0, target.Width - 2, target.Height));
int topCrop = 0;
var cutBitmap2 = NikseBitmapImageSplitter.CropTopAndBottom(cutBitmap, out topCrop);
if (cutBitmap2.Height != target.Height)
FindBestMatchNew(ref index, ref smallestDifference, ref smallestIndex, cutBitmap2, _binaryOcrDb);
}
}
//.........这里部分代码省略.........