private void UpCam_TakeSnapshot() { SelectCamera(UpCamera); DisplayText("UpCam_TakeSnapshot()"); UpCamera.SnapshotRotation = Cnc.CurrentA; UpCamera.BuildMeasurementFunctionsList(UpcamSnapshot_dataGridView); UpCamera.TakeSnapshot(); DownCamera.SnapshotOriginalImage = new Bitmap(UpCamera.SnapshotImage); DownCamera.SnapshotImage = new Bitmap(UpCamera.SnapshotImage); // We need a copy of the snapshot to scale it, in 24bpp format. See http://stackoverflow.com/questions/2016406/converting-bitmap-pixelformats-in-c-sharp Bitmap Snapshot24bpp = new Bitmap(640, 480, System.Drawing.Imaging.PixelFormat.Format24bppRgb); using (Graphics gr = Graphics.FromImage(Snapshot24bpp)) { gr.DrawImage(UpCamera.SnapshotOriginalImage, new Rectangle(0, 0, 640, 480)); } // scale: double Xscale = Properties.Settings.Default.UpCam_XmmPerPixel / Properties.Settings.Default.DownCam_XmmPerPixel; double Yscale = Properties.Settings.Default.UpCam_YmmPerPixel / Properties.Settings.Default.DownCam_YmmPerPixel; double zoom = UpCamera.GetMeasurementZoom(); Xscale = Xscale / zoom; Yscale = Yscale / zoom; int SnapshotSizeX = (int)(Xscale * 640); int SnapshotSizeY = (int)(Yscale * 480); // SnapshotSize is the size (in pxls) of upcam snapshot, scaled so that it draws in correct size on downcam image. ResizeNearestNeighbor RezFilter = new ResizeNearestNeighbor(SnapshotSizeX, SnapshotSizeY); Bitmap ScaledShot = RezFilter.Apply(Snapshot24bpp); // and this is the scaled image // Mirror: Mirror MirrFilter = new Mirror(false, true); MirrFilter.ApplyInPlace(ScaledShot); // Clear DownCam image Graphics DownCamGr = Graphics.FromImage(DownCamera.SnapshotImage); DownCamGr.Clear(Color.Black); // Embed the ScaledShot to it. Upper left corner of the embedding is: int X = 320 - SnapshotSizeX / 2; int Y = 240 - SnapshotSizeY / 2; DownCamGr.DrawImage(ScaledShot, X, Y, SnapshotSizeX, SnapshotSizeY); DownCamera.SnapshotImage.MakeTransparent(Color.Black); // DownCam Snapshot is ok, copy it to original too DownCamera.SnapshotOriginalImage = new Bitmap(DownCamera.SnapshotImage); DownCamera.SnapshotRotation = Cnc.CurrentA; }
// ========================================================================================================== private Bitmap MirrorFunct(Bitmap frame) { Mirror Mfilter = new Mirror(false, true); // apply the MirrFilter Mfilter.ApplyInPlace(frame); return (frame); }
private void cam_NewFrameMirrortwo(object sender, NewFrameEventArgs eventArgs) { //Evento para espelhar espelhar try { Bitmap bitmirror = (Bitmap)eventArgs.Frame.Clone(); Mirror filter = new Mirror(false, true); filter.ApplyInPlace(bitmirror); pbCamera.Image = bitmirror; } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message); } }