public RadBitmapData Decode(Stream stream) { Metafile metaFile = new Metafile(stream); int width = metaFile.Width; int height = metaFile.Height; float scaleFactor = 1f; if (metaFile.Width > maxPixelSize || metaFile.Height > maxPixelSize) { scaleFactor = Math.Max((float)metaFile.Width / (float)maxPixelSize, (float)metaFile.Height / (float)maxPixelSize); width = (int)(width / scaleFactor); height = (int)(height / scaleFactor); } // Create a PictureBox control and load the metafile PictureBox box = new PictureBox(); box.Width = width; box.Height = height; box.BackColor = Color.White; box.SizeMode = PictureBoxSizeMode.StretchImage; box.Image = metaFile; // Create snapshot of the PictureBox and save it as a bitmap Bitmap bmp = new Bitmap(width, height); box.DrawToBitmap(bmp, new Rectangle(0, 0, width, height)); //load the image in WPF RadBitmap result = null; RadBitmapData data = null; using (MemoryStream output = new MemoryStream()) { BitmapImage image = new BitmapImage(); image.BeginInit(); bmp.Save(output, this.encoder, null); output.Seek(0, SeekOrigin.Begin); image.StreamSource = output; image.EndInit(); result = new RadBitmap(image); data = new RadBitmapData(result.Width, result.Height, result.GetPixels()); } return data; }
public void saveImages() { if (dt.Rows.Count <= 0) { return; } using (var bitmap = new Bitmap(PicBox.Width, PicBox.Height)) { PicBox.DrawToBitmap(bitmap, PicBox.ClientRectangle); SaveFileDialog dlg = new SaveFileDialog(); dlg.FileName = "*"; dlg.DefaultExt = "bmp"; dlg.ValidateNames = true; dlg.Filter = "Bitmap Image (.bmp)|*.bmp|Gif Image (.gif)|*.gif|JPEG Image (.jpeg)|*.jpeg|Png Image (.png)|*.png"; if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { bitmap.Save(dlg.FileName); } } }
private void pauseToolStripMenuItem_Click(object sender, EventArgs e) { //pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize; if (capture == null) { return; } try { Mat m = new Mat(); capture.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.PosFrames, 501); capture.Read(m); //pictureBox1.Image = m.Bitmap; //Clone PictureBox System.Windows.Forms.PictureBox a = new System.Windows.Forms.PictureBox(); a.Image = m.Bitmap; a.Width = 500; a.Height = 500; a.SizeMode = PictureBoxSizeMode.AutoSize; //Crop image int rectW = 150; int rectH = 150; Bitmap bmp2 = new Bitmap(a.Width, a.Height); a.DrawToBitmap(bmp2, a.ClientRectangle); Bitmap crpImg = new Bitmap(rectW, rectH); for (int i = 0; i < rectW; i++) { for (int y = 0; y < rectH; y++) { Color pxlclr = bmp2.GetPixel(1300 + i, 750 + y); crpImg.SetPixel(i, y, pxlclr); } } a.SizeMode = PictureBoxSizeMode.Zoom; a.Image = (Image)crpImg; this.pictureBox1.Image = a.Image; //pictureBox2.Image = m.Bitmap; //pictureBox1.Image = m.Bitmap; /* * while (true) * { * Mat m = new Mat(); * capture.Read(m); * * if (!m.IsEmpty) * { * pictureBox1.Image = m.Bitmap; * DetectText(m.ToImage<Bgr, byte>()); * double fps = capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.Fps); * await Task.Delay(1000 / Convert.ToInt32(fps)); * } * else * { * break; * } * }*/ } catch (Exception ex) { MessageBox.Show(ex.Message); } }