本文整理汇总了C#中Nikse.SubtitleEdit.Logic.NikseBitmap类的典型用法代码示例。如果您正苦于以下问题:C# NikseBitmap类的具体用法?C# NikseBitmap怎么用?C# NikseBitmap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NikseBitmap类属于Nikse.SubtitleEdit.Logic命名空间,在下文中一共展示了NikseBitmap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NikseBitmap
public NikseBitmap(NikseBitmap input)
{
Width = input.Width;
Height = input.Height;
_bitmapData = new byte[input._bitmapData.Length];
Buffer.BlockCopy(input._bitmapData, 0, _bitmapData, 0, _bitmapData.Length);
}
示例2: ImageSplitterItem
public ImageSplitterItem(int x, int y, NikseBitmap bitmap)
{
X = x;
Y = y;
NikseBitmap = bitmap;
SpecialCharacter = null;
}
示例3: 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));
}
示例4: TestMethodBinOcrSaveLoad
public void TestMethodBinOcrSaveLoad()
{
string tempFileName = Path.GetTempFileName();
var db = new BinaryOcrDb(tempFileName);
var nbmp = new NikseBitmap(2, 2);
nbmp.SetPixel(0, 0, Color.Transparent);
nbmp.SetPixel(1, 0, Color.Transparent);
nbmp.SetPixel(1, 0, Color.Transparent);
nbmp.SetPixel(1, 1, Color.White);
var bob = new BinaryOcrBitmap(nbmp);
bob.Text = "Debug";
db.Add(bob);
nbmp.SetPixel(0, 0, Color.White);
var bob2 = new BinaryOcrBitmap(nbmp);
bob2.X = 2;
bob2.Y = 4;
bob2.Text = "tt";
bob2.Italic = true;
bob2.ExpandCount = 2;
bob2.ExpandedList = new System.Collections.Generic.List<BinaryOcrBitmap>();
bob2.ExpandedList.Add(bob2);
db.Add(bob2);
db.Save();
db = new BinaryOcrDb(tempFileName, true);
Assert.IsTrue(db.CompareImages.Count == 1);
Assert.IsTrue(db.CompareImagesExpanded.Count == 1);
Assert.IsTrue(bob.Width == db.CompareImages[0].Width);
Assert.IsTrue(bob.Height == db.CompareImages[0].Height);
Assert.IsTrue(bob.NumberOfColoredPixels == db.CompareImages[0].NumberOfColoredPixels);
Assert.IsTrue(bob.Hash == db.CompareImages[0].Hash);
Assert.IsTrue(bob.Italic == db.CompareImages[0].Italic);
Assert.IsTrue(bob.ExpandCount == db.CompareImages[0].ExpandCount);
Assert.IsTrue(bob.Text == db.CompareImages[0].Text);
Assert.IsTrue(bob2.Width == db.CompareImagesExpanded[0].Width);
Assert.IsTrue(bob2.Height == db.CompareImagesExpanded[0].Height);
Assert.IsTrue(bob2.NumberOfColoredPixels == db.CompareImagesExpanded[0].NumberOfColoredPixels);
Assert.IsTrue(bob2.Hash == db.CompareImagesExpanded[0].Hash);
Assert.IsTrue(bob2.Italic == db.CompareImagesExpanded[0].Italic);
Assert.IsTrue(bob2.ExpandCount == db.CompareImagesExpanded[0].ExpandCount);
Assert.IsTrue(bob2.Text == db.CompareImagesExpanded[0].Text);
Assert.IsTrue(bob2.X == db.CompareImagesExpanded[0].X);
Assert.IsTrue(bob2.Y == db.CompareImagesExpanded[0].Y);
try
{
File.Delete(tempFileName);
}
catch
{
}
}
示例5: 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;
}
示例6: Initialize
internal void Initialize(Bitmap vobSubImage, ImageSplitterItem character, Point position, bool italicChecked, bool showShrink)
{
listBoxLinesForeground.Items.Clear();
listBoxlinesBackground.Items.Clear();
NikseBitmap nbmp = new NikseBitmap(vobSubImage);
nbmp.ReplaceTransparentWith(Color.Black);
vobSubImage = nbmp.GetBitmap();
radioButtonHot.Checked = true;
ShrinkSelection = false;
ExpandSelection = false;
textBoxCharacters.Text = string.Empty;
_nocrChar = new NOcrChar();
_nocrChar.MarginTop = character.Y - character.ParentY;
_imageWidth = character.NikseBitmap.Width;
_imageHeight = character.NikseBitmap.Height;
_drawLineOn = false;
_warningNoNotForegroundLinesShown = false;
buttonShrinkSelection.Visible = showShrink;
if (position.X != -1 && position.Y != -1)
{
StartPosition = FormStartPosition.Manual;
Left = position.X;
Top = position.Y;
}
pictureBoxSubtitleImage.Image = vobSubImage;
pictureBoxCharacter.Image = character.NikseBitmap.GetBitmap();
Bitmap org = (Bitmap)vobSubImage.Clone();
Bitmap bm = new Bitmap(org.Width, org.Height);
Graphics g = Graphics.FromImage(bm);
g.DrawImage(org, 0, 0, org.Width, org.Height);
g.DrawRectangle(Pens.Red, character.X, character.Y, character.NikseBitmap.Width, character.NikseBitmap.Height - 1);
g.Dispose();
pictureBoxSubtitleImage.Image = bm;
pictureBoxCharacter.Top = labelCharacters.Top + 16;
SizePictureBox();
checkBoxItalic.Checked = italicChecked;
_history = new List<NOcrChar>();
_historyIndex = -1;
_nocrChar.Width = _imageWidth;
_nocrChar.Height = _imageHeight;
GenerateLineSegments(150, false, _nocrChar, new NikseBitmap(pictureBoxCharacter.Image as Bitmap));
ShowOcrPoints();
pictureBoxCharacter.Invalidate();
}
示例7: ManagedBitmap
public ManagedBitmap(NikseBitmap nbmp)
{
Width = nbmp.Width;
Height = nbmp.Height;
_colors = new Color[Width * Height];
for (int y = 0; y < Height; y++)
{
for (int x = 0; x < Width; x++)
{
this.SetPixel(x, y, nbmp.GetPixel(x, y));
}
}
}
示例8: Initialize
internal void Initialize(Bitmap bitmap, int pixelsIsSpace, bool rightToLeft, NOcrDb nOcrDb, VobSubOcr vobSubOcr)
{
_bitmap = bitmap;
var nbmp = new NikseBitmap(bitmap);
nbmp.ReplaceNonWhiteWithTransparent();
bitmap = nbmp.GetBitmap();
_bitmap2 = bitmap;
_nocrChars = nOcrDb.OcrCharacters;
_matchList = new List<VobSubOcr.CompareMatch>();
_vobSubOcr = vobSubOcr;
int minLineHeight = 6;
_imageList = NikseBitmapImageSplitter.SplitBitmapToLettersNew(nbmp, pixelsIsSpace, rightToLeft, Configuration.Settings.VobSubOcr.TopToBottom, minLineHeight);
// _imageList = NikseBitmapImageSplitter.SplitBitmapToLetters(nbmp, pixelsIsSpace, rightToLeft, Configuration.Settings.VobSubOcr.TopToBottom);
int index = 0;
while (index < _imageList.Count)
{
ImageSplitterItem item = _imageList[index];
if (item.NikseBitmap == null)
{
listBoxInspectItems.Items.Add(item.SpecialCharacter);
_matchList.Add(null);
}
else
{
nbmp = item.NikseBitmap;
nbmp.ReplaceNonWhiteWithTransparent();
item.Y += nbmp.CropTopTransparent(0);
nbmp.CropTransparentSidesAndBottom(0, true);
nbmp.ReplaceTransparentWith(Color.Black);
//get nocr matches
Nikse.SubtitleEdit.Forms.VobSubOcr.CompareMatch match = vobSubOcr.GetNOcrCompareMatchNew(item, nbmp, nOcrDb, false, false);
if (match == null)
{
listBoxInspectItems.Items.Add("?");
_matchList.Add(null);
}
else
{
listBoxInspectItems.Items.Add(match.Text);
_matchList.Add(match);
}
}
index++;
}
}
示例9: Initialize
internal void Initialize(Bitmap vobSubImage, ImageSplitterItem character, Point position, bool italicChecked, bool showShrink, VobSubOcr.CompareMatch bestGuess, List<VobSubOcr.ImageCompareAddition> additions, VobSubOcr vobSubForm)
{
NikseBitmap nbmp = new NikseBitmap(vobSubImage);
nbmp.ReplaceTransparentWith(Color.Black);
vobSubImage = nbmp.GetBitmap();
radioButtonHot.Checked = true;
ShrinkSelection = false;
ExpandSelection = false;
textBoxCharacters.Text = string.Empty;
_vobSubForm = vobSubForm;
_additions = additions;
_nocrChar = new NOcrChar();
_nocrChar.MarginTop = character.Y - character.ParentY;
_imageWidth = character.NikseBitmap.Width;
_imageHeight = character.NikseBitmap.Height;
_drawLineOn = false;
_warningNoNotForegroundLinesShown = false;
buttonShrinkSelection.Visible = showShrink;
if (position.X != -1 && position.Y != -1)
{
StartPosition = FormStartPosition.Manual;
Left = position.X;
Top = position.Y;
}
pictureBoxSubtitleImage.Image = vobSubImage;
pictureBoxCharacter.Image = character.NikseBitmap.GetBitmap();
Bitmap org = (Bitmap)vobSubImage.Clone();
Bitmap bm = new Bitmap(org.Width, org.Height);
Graphics g = Graphics.FromImage(bm);
g.DrawImage(org, 0, 0, org.Width, org.Height);
g.DrawRectangle(Pens.Red, character.X, character.Y, character.NikseBitmap.Width, character.NikseBitmap.Height - 1);
g.Dispose();
pictureBoxSubtitleImage.Image = bm;
pictureBoxCharacter.Top = labelCharacters.Top + 16;
SizePictureBox();
checkBoxItalic.Checked = italicChecked;
_history = new List<NOcrChar>();
_historyIndex = -1;
}
示例10: listBoxSubtitles_SelectedIndexChanged
private void listBoxSubtitles_SelectedIndexChanged(object sender, EventArgs e)
{
int idx = listBoxSubtitles.SelectedIndex;
if (idx < 0)
return;
int pid = _tsParser.SubtitlePacketIds[listBoxTracks.SelectedIndex];
var list = _tsParser.GetDvbSubtitles(pid);
var dvbBmp = list[idx].GetActiveImage();
var nDvbBmp = new NikseBitmap(dvbBmp);
nDvbBmp.CropTopTransparent(2);
nDvbBmp.CropTransparentSidesAndBottom(2, true);
dvbBmp.Dispose();
var oldImage = pictureBox1.Image;
pictureBox1.Image = nDvbBmp.GetBitmap();
if (oldImage != null)
oldImage.Dispose();
}
示例11: 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;
}
示例12: IsVerticalLineTransparent
private static bool IsVerticalLineTransparent(NikseBitmap bmp, ref int y, int x)
{
for (y = 0; y < bmp.Height - 1; y++)
{
var argb = bmp.GetPixelColors(x, y);
if (argb[0] < 10 || IsColorClose(argb[0], argb[1], argb[2], argb[3], Color.Black, 280)) // still dark color...
{
}
else
{
return false;
}
}
return true;
}
示例13: IsCursiveVerticalLineTransparent
private static bool IsCursiveVerticalLineTransparent(NikseBitmap bmp, int size, int y, int x, List<Point> cursivePoints)
{
bool cursiveOk = true;
int newY = y;
int newX = x;
while (cursiveOk && newY < bmp.Height - 1)
{
Color c0 = bmp.GetPixel(newX, newY);
if (c0.A == 0 || IsColorClose(c0, Color.Black, 280))
{
newY++;
}
else
{
byte[] c1 = bmp.GetPixelColors(newX - 1, newY - 1);
byte[] c2 = bmp.GetPixelColors(newX - 1, newY);
if ((c1[0] == 0 || IsColorClose(c1[0], c1[1], c1[2], c1[3], Color.Black, 280)) && // still dark color...
(c2[0] == 0 || IsColorClose(c2[0], c2[1], c2[2], c2[3], Color.Black, 280)))
{
cursivePoints.Add(new Point(newX, newY));
if (newX > 1)
newX--;
else
cursiveOk = false;
newY++;
}
else
{
cursiveOk = false;
}
}
if (newX < x - size)
cursiveOk = false;
}
return cursiveOk;
}
示例14: 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);
}
}
}
示例15: 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;
}