private void LoadBitmapDisplayViewScreen(string filePath) { Image image = Image.FromFile(filePath); PictureBoxMain.Image = image; PictureBoxMain.SizeMode = PictureBoxSizeMode.StretchImage; PictureBoxMain.Refresh(); label_message.Text = Path.GetFileName(filePath); m_bmp = new Bitmap(image); label_message.Text = "w= " + m_bmp.Width + " h= " + m_bmp.Height; }
private void Display3BytePixelDataToPictureBox(byte[] col, int w, int h, int BitsPerPixel) { int x, y; byte[] raw = new byte[w * h * 4]; for (y = 0; y < h; y++) { for (x = 0; x < w; x++) { raw[(4 * w) * (y) + (4 * x) + 0] = col[(3 * w) * (y) + (3 * x) + 0]; raw[(4 * w) * (y) + (4 * x) + 1] = col[(3 * w) * (y) + (3 * x) + 1]; raw[(4 * w) * (y) + (4 * x) + 2] = col[(3 * w) * (y) + (3 * x) + 2]; } } Bitmap graybmp = RawTo32BitsBitmap(raw, w, h); PictureBoxMain.Image = graybmp; PictureBoxMain.SizeMode = PictureBoxSizeMode.StretchImage; PictureBoxMain.Refresh(); }
/// <summary> /// Zooming out and in via mouse wheel handler /// </summary> private void PictureViewerFormMain_MouseWheel(object sender, MouseEventArgs e) { double modifier = 1.0 + 1.0 / ((double)e.Delta / 30.0); zoom *= modifier; if (GraphSettings.ImageWidth * zoom <= Width && zoom < 1) { zoom = (double)PictureBoxMain.Width / (double)GraphSettings.ImageWidth; } int lastW = PictureBoxMain.Width; int lastH = PictureBoxMain.Height; PictureBoxMain.SuspendLayout(); PictureBoxMain.Width = (int)(GraphSettings.ImageWidth * zoom); PictureBoxMain.Height = (int)(GraphSettings.ImageHeight * zoom); PictureBoxMain.Left = (int)(PictureBoxMain.Location.X + (lastW - GraphSettings.ImageWidth * zoom) / 2); PictureBoxMain.Top = (int)(PictureBoxMain.Location.Y + (lastH - GraphSettings.ImageHeight * zoom) / 2); PictureBoxMain.ResumeLayout(); }
private void ButtonRGBVision_Click(object sender, EventArgs e) { if (PictureBoxMain.Image == null) { return; } int w = m_bmp.Width; int h = m_bmp.Height; byte[] col = Get3BytePixelDataFromBitmap(m_bmp, w, h); byte[] R = new byte[w * h * 3]; byte[] G = new byte[w * h * 3]; byte[] B = new byte[w * h * 3]; intPtr = GetProcAddress(m_hDLL, "EngineSplitRGBchannels"); EngineVisionRGBCS SplitRGBchannels = (EngineVisionRGBCS)Marshal.GetDelegateForFunctionPointer(intPtr, typeof(EngineVisionRGBCS)); SplitRGBchannels(R, G, B, col, w, h); Bitmap bmpR = Get32BitBitmapFrom24BitPixelData(R, w, h, 24); Bitmap bmpG = Get32BitBitmapFrom24BitPixelData(G, w, h, 24); Bitmap bmpB = Get32BitBitmapFrom24BitPixelData(B, w, h, 24); bmpR.Save("R.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); bmpG.Save("G.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); bmpB.Save("B.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); PictureBoxMain.Image = bmpG; PictureBoxMain.SizeMode = PictureBoxSizeMode.StretchImage; PictureBoxMain.Refresh(); label_message.Text = "w= " + PictureBoxMain.Image.Width + " h= " + PictureBoxMain.Image.Height; }
private void ButtonYUVVision_Click(object sender, EventArgs e) { if (PictureBoxMain.Image == null) { return; } int w = m_bmp.Width; int h = m_bmp.Height; byte[] col = Get3BytePixelDataFromBitmap(m_bmp, w, h); byte[] Y = new byte[w * h * 3]; byte[] U = new byte[w * h * 3]; byte[] V = new byte[w * h * 3]; intPtr = GetProcAddress(m_hDLL, "EngineSplitYUVchannels"); EngineVisionYUVCS SplitYUVchannels = (EngineVisionYUVCS)Marshal.GetDelegateForFunctionPointer(intPtr, typeof(EngineVisionYUVCS)); SplitYUVchannels(Y, U, V, col, w, h); Bitmap bmpY = Get32BitBitmapFrom24BitPixelData(Y, w, h, 24); Bitmap bmpU = Get32BitBitmapFrom24BitPixelData(U, w, h, 24); Bitmap bmpV = Get32BitBitmapFrom24BitPixelData(V, w, h, 24); bmpY.Save("Y.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); bmpU.Save("U.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); bmpV.Save("V.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); PictureBoxMain.Image = bmpY; PictureBoxMain.SizeMode = PictureBoxSizeMode.StretchImage; PictureBoxMain.Refresh(); label_message.Text = "w= " + PictureBoxMain.Image.Width + " h= " + PictureBoxMain.Image.Height; }