本文整理汇总了C#中Image.ToBitmap方法的典型用法代码示例。如果您正苦于以下问题:C# Image.ToBitmap方法的具体用法?C# Image.ToBitmap怎么用?C# Image.ToBitmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image.ToBitmap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Form1_Load
private void Form1_Load(object sender, EventArgs e)
{
if (openImageFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Bgr drawColor = new Bgr(Color.Blue);
try
{
Image<Bgr, Byte> image = new Image<Bgr, byte>(openImageFileDialog.FileName);
original.Image = image.ToBitmap();
original.SizeMode = PictureBoxSizeMode.Zoom;
using (Image<Gray, byte> gray = image.Convert<Gray, Byte>())
{
_ocr.Recognize(gray);
Tesseract.Charactor[] charactors = _ocr.GetCharactors();
foreach (Tesseract.Charactor c in charactors)
{
image.Draw(c.Region, drawColor, 1);
}
processed.Image = image.ToBitmap();
processed.SizeMode = PictureBoxSizeMode.Zoom;
//String text = String.Concat( Array.ConvertAll(charactors, delegate(Tesseract.Charactor t) { return t.Text; }) );
String text = _ocr.GetText();
ocrTextBox.Text = text;
}
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
}
}
示例2: button1_Click
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog Openfile = new OpenFileDialog();
if (Openfile.ShowDialog() == DialogResult.OK)
{
Image<Bgr, Byte> originalImage = new Image<Bgr, byte>(Openfile.FileName);
Image<Gray, Byte> grayImage = originalImage.Convert<Gray, Byte>();
grayImage._SmoothGaussian(3);
CvInvoke.cvAdaptiveThreshold(grayImage, grayImage, 255, ADAPTIVE_THRESHOLD_TYPE.CV_ADAPTIVE_THRESH_MEAN_C, THRESH.CV_THRESH_BINARY, 75, 10);
grayImage._Not();
//ArrayList lines = new ArrayList();
LineSegment2D[] lines = grayImage.HoughLinesBinary(
1, //Distance resolution in pixel-related units
Math.PI / 45.0, //Angle resolution measured in radians.
20, //threshold
30, //min Line width
10 //gap between lines
)[0]; //Get the lines from the first channel
#region draw lines
foreach (LineSegment2D line in lines)
originalImage.Draw(line, new Bgr(Color.Red), 1);
#endregion
pictureBox1.Image = originalImage.ToBitmap();
}
}
示例3: UploadButton_Click
protected void UploadButton_Click(object sender, EventArgs e)
{
try
{
if (!((FileUpload1.PostedFile.ContentType == "image/jpeg") ||
(FileUpload1.PostedFile.ContentType == "image/png") ||
(FileUpload1.PostedFile.ContentType == "image/gif") ||
(FileUpload1.PostedFile.ContentType == "image/bmp"))) throw new Exception("Неизвестный тип файла");
string PhotoFolder = Request.PhysicalApplicationPath + @"\photos\";
if (!Directory.Exists(PhotoFolder)) Directory.CreateDirectory(PhotoFolder);
string extention = Path.GetExtension(FileUpload1.FileName);
string uniqueName = Path.ChangeExtension(FileUpload1.FileName, DateTime.Now.Ticks.ToString());
string upFile = Path.Combine(PhotoFolder, uniqueName + extention);
FileUpload1.SaveAs(upFile);
//Распознование лиц
HaarCascade haarCascade = new HaarCascade(Request.PhysicalApplicationPath + @"\haarcascade_frontalface_alt2.xml");
Image<Bgr, Byte> image = new Image<Bgr, Byte>(upFile);
Image<Gray, Byte> grayImage = image.Convert<Gray, Byte>();
Bitmap srcImage = image.ToBitmap();
var detectedFaces = grayImage.DetectHaarCascade(haarCascade)[0];
foreach (var face in detectedFaces)
{
Image<Bgr, Byte> imFace = image.Copy(face.rect);
//Пикселизация (фактор подобран эмпирически)
//при данном факторе одиноково хорошо пикселизируются и большие и маленькие лица
double factor = 0.02 + (double)10 / (double)face.rect.Height;
imFace = imFace.Resize(factor, 0);
imFace = imFace.Resize(1 / factor, 0);
Bitmap faceBitmap = imFace.ToBitmap();
using (Graphics grD = Graphics.FromImage(srcImage))
{
grD.DrawImage(faceBitmap, new Point(face.rect.Left, face.rect.Top));
}
}
string uniqueName_processed = uniqueName + "_processed";
srcImage.Save(Path.Combine(PhotoFolder, uniqueName_processed + extention));
imgTitle.Visible = true;
Image1.ImageUrl = "photos/" + uniqueName_processed + extention;
}
catch (Exception ex)
{
Session["ErrorMsg"] = ex.Message;
Response.Redirect("~/error.aspx", true);
}
}
示例4: SelectPerpetratorForm
public SelectPerpetratorForm(Image<Bgr, byte> perpetrator_frame)
{
InitializeComponent();
Size new_size = new Size(perpetrator_frame_picture_box.Width,perpetrator_frame_picture_box.Height);
perpetrator_frame_picture_box.Image = FramesManager.ResizeBitmap(perpetrator_frame.ToBitmap(), new_size);
this.frame_with_perpetrator = perpetrator_frame;
}
示例5: FloodFillTest
public void FloodFillTest()
{
// Create a Square
Point[] square = new Point[4];
square[0] = new Point(25, 25);
square[1] = new Point(75, 25);
square[2] = new Point(75, 75);
square[3] = new Point(25, 75);
// Create an Original Image
var original = new Image<Bgr, Byte>(100, 100, new Bgr(255, 0, 0));
original.FillConvexPoly(square, new Bgr(Color.Green));
// Create an Expected Output Image
var expected = new Emgu.CV.Image<Bgr, Byte>(100, 100, new Bgr(Preprocessing.MASK_COLOR));
expected.FillConvexPoly(square, new Bgr(Color.White));
// Perform the Flood fill
Console.WriteLine("Perform Flood Fill ... ");
var actual = new Emgu.CV.Image<Bgr, Byte>(Preprocessing.FloodFill(original.ToBitmap(), 0, 0, 1));
bool identical = true;
for (int ii = 0; ii < expected.Width; ii++)
{
for (int jj = 0; jj < expected.Height; jj++)
{
identical = identical && (Utility.IsEqual(expected[jj, ii], actual[jj, ii]));
}
}
Assert.IsTrue(identical);
}
示例6: GreyscaleImage
public static Image<Bgr, Byte> GreyscaleImage(Image<Bgr, Byte> sourceImage)
{
//float[,] weights = new float[3, 3]
//{
// { 0.3333f, 0.3333f, 0.3333f }, // "flat" weighting - may as well use the emgu version
// { 0.3000f, 0.5900f, 0.1100f }, // standard NTSC RGB luminence weights
// { 0.3086f, 0.6094f, 0.0820f } // modified weights according to http://www.graficaobscura.com/matrix/index.html
//};
ColorMatrix colorMatrix = new ColorMatrix(new float[][]
{
new float[] {0.3000f, 0.3000f, 0.3000f, 0, 0},
new float[] {0.5900f, 0.5900f, 0.5900f, 0, 0},
new float[] {0.1100f, 0.1100f, 0.1100f, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1}
});
// apply the colourmatrix to a set of image attributes
ImageAttributes attributes = new ImageAttributes();
attributes.SetColorMatrix(colorMatrix);
// Convert the Iimage to a bmp,
Bitmap sourceBMP = sourceImage.ToBitmap();
// use it to make a blank bmp to itiate a graphics object
Bitmap tempBMP = new Bitmap(sourceBMP.Width, sourceBMP.Height);
Graphics graphic = Graphics.FromImage(tempBMP);
// apply the source image and the color matrix (via the attributes) to the graphics obj
graphic.DrawImage(sourceBMP, new Rectangle(0, 0, sourceBMP.Width, sourceBMP.Height), 0, 0, sourceBMP.Width, sourceBMP.Height, GraphicsUnit.Pixel, attributes);
return new Image<Bgr, byte>(tempBMP);
}
示例7: Canny
public Bitmap Canny(Bitmap image)
{
Image<Gray, Byte> cannyimg = new Image<Gray, Byte>(image);
// cannyimg = cannyimg.Canny(10, 19);
cannyimg = cannyimg.Canny(13, 45);
return cannyimg.ToBitmap();
}
示例8: ExtractContour
public List<LineSegment2D> ExtractContour(Image<Bgr, byte> img,out Image<Bgr, byte> temp )
{
List<LineSegment2D> ListOfLines = new List<LineSegment2D>();
Image<Gray, byte> gray = new Image<Gray, byte>(img.ToBitmap());
gray.ThresholdBinary(new Gray(149), new Gray(255));
gray._Dilate(1);
gray._Erode(1);
img.ROI = new Rectangle(new Point(0, Img_Height - Roi_Height), new Size(Img_Width, Roi_Height));
gray.ROI = new Rectangle(new Point(0, Img_Height - Roi_Height), new Size(Img_Width, Roi_Height));
Image<Gray, byte> canny = gray.Canny(150, 50);
//canny.Save("D:\\temp\\canny.jpg");
Image<Bgr, byte> lineimage = img;
lines = canny.HoughLines(1, 2, 3, Math.PI / 180, 150, 80, 400);
foreach (LineSegment2D line in lines[0])
{
float theta = line.Direction.Y / line.Direction.X;
float c = line.P1.Y - theta * line.P1.X;
if (Math.Abs(theta) > 0.1 && Math.Abs(theta) < 0.9&&c<300)
{
lineimage.Draw(line, new Bgr(0, 0, 255), 1);
ListOfLines.Add(line);
}
}
temp = lineimage;
//lineimage.Save("D:\\temp\\HoughLines.jpg");
return ListOfLines;
}
示例9: GetImage
public Bitmap GetImage()
{
viewer.Image = capture.QueryFrame();
img = (Image<Bgr, Byte>)viewer.Image;
img = img.Rotate(Config.Angle, new Bgr(255, 255, 255), false);
img.ROI = Config.Rect;
return img.ToBitmap();
}
示例10: Deblur
/// <summary>
/// Deblur bitmap with the Fastest Fourier Transform
/// </summary>
/// <returns>Deblurred bitmap</returns>
public Bitmap Deblur(Bitmap bitmap)
{
using (var image = new Image<Bgr, double>(bitmap))
{
image.Data = Deblur(image.Data);
return image.ToBitmap();
}
}
示例11: button1_Click
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog Openfile = new OpenFileDialog();
if (Openfile.ShowDialog() == DialogResult.OK)
{
Image<Bgr, Byte> My_Image = new Image<Bgr, byte>(Openfile.FileName);
pictureBox1.Image = My_Image.ToBitmap();
}
}
示例12: Web
// Конструктор для выделенной области
public Web(Image<Bgr,byte> pict, TextBox stat)
{
input = pict;
FileInfo fin = new FileInfo("Target.txt"); // Создание файла весов
StreamWriter Wr = fin.CreateText(); // Режим записи в файл весов
Bitmap bmp = new Bitmap(input.ToBitmap());
stat.Text += "Выбранная область: " + Environment.NewLine;
KodWeight(Wr, bmp, stat); // Запись данных в файл весов и его отображение в окне статистики
Wr.Close();
}
示例13: CheckMatch
public bool CheckMatch(Image<Bgr, byte> queryframe)
{
Image<Gray, byte> mG = new Image<Gray, byte>(model.ToBitmap());
Image<Gray, byte> oG = new Image<Gray, byte>(queryframe.ToBitmap());
Image<Bgr, byte> res = _cpu.DrawResult(mG, oG, out _area, _areathreshold, out _center);
Result = res;
// The matching result already comes out now, but I need to make it more stable
// And trigger the stop signal at the right time.
_statusQ.EnQ(_area);
return _statusQ.CheckMatch(500);
}
示例14: ConvertImage
public BitmapImage ConvertImage(Image<Bgr, Byte> frame)
{
MemoryStream ms = new MemoryStream();
frame.ToBitmap().Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
BitmapImage image = new BitmapImage();
image.BeginInit();
ms.Seek(0, SeekOrigin.Begin);
image.StreamSource = ms;
image.EndInit();
return image;
}
示例15: GetBitmapSource
System.Windows.Media.Imaging.BitmapSource GetBitmapSource(Image<Bgr, Byte> _image)
{
BitmapImage bi = new BitmapImage();
bi.BeginInit();
MemoryStream ms = new MemoryStream();
_image.ToBitmap().Save(ms, ImageFormat.Bmp);
ms.Seek(0, SeekOrigin.Begin);
bi.StreamSource = ms;
bi.EndInit();
//Using the freeze function to avoid cross thread operations
bi.Freeze();
return bi;
}