Camera code code

xiaoxiao2021-03-06  69

In the camera, there is no time, not my original, lest someone gossip

Using system; using system.runtime.interopservices;

Namespace Wuyin.ShoesManager {///

/// vediocapture's summary description.

/// public class VedioCapture {private int hCaptureM; private bool isUnLoad = false; public VedioCapture () {} [DllImport ( "avicap32.dll")] private static extern int capCreateCaptureWindow (string strWindowName, int dwStyle, int X, int y, int hwdparent, int nid; [DLLIMPORT ("User32.dll")] private static extern int sendMessage (int hWnd, int WMSG, INT WPARAM, INT LPARAM); [DLLIMPORT "user32.dll")] private static extern int SendMessage (int hwnd, int wMsg, int wParam, string lParam); [DllImport ( "Kernel32.dll")] private static extern bool CloseHandle (int hObject); public bool Initialize ( System.Windows.Forms.Control aContainer, int intWidth, int intHeight) {hCaptureM = capCreateCaptureWindow ( "", 0x40000000 | 0x10000000, 0,0, intWidth, intHeight, aContainer.Handle.ToInt32 (), 1); if (hCaptureM = = 0) Return False; int RET = SENDMESSAGE (HcApturem, 1034, 0); if (RET == 0) {CloseHandle (HcApturem); Return False;} // WM_CAP_SET_PREVIEW RET = SendMessage (Hcapturem, 1074, 1, 0); if (RET == 0) {this.unload (); return false;} // WM_CAP_SET_SCALE RET = SendMessage (Hcapturem, 1077, 1, 0); if (RET == 0) {this.unload (); returnaf; } // WM_CAP_SET_PREVIEWRATE RET =

SendMessage (Hcapturem, 1076, 66, 0); if (RET == 0) {this.unload (); returnial;} return true;} public void singleframebegin () {// int RET = SendMessage (Hcapturem, 1094, 0, 0); PUBLIC VOID SINGLRAMEEND () {// int RET = SendMessage (Hcapturem, 1095, 0, 0);

public void SingleFrameMode () {// WM_CAP_GRAB_FRAME int ret = SendMessage (hCaptureM, 1084, 0, 0); // WM_CAP_SET_PREVIEW // int ret = SendMessage (hCaptureM, 1074, 0, 0); // WM_CAP_SINGLE_FRAME // ret = SendMessage (Hcapturem, 1096, 0, 0); PUBLIC VOID PreviewMode () {int RET = SendMessage (Hcapturem, 1074, 1, 0);}

Public void unload () {int RET = SendMessage (Hcapturem, 1035, 0, 0); CloseHandle (this.hcapturem); iSunload = true;}

Public void copyspace () {int RET = SendMessage (Hcapturem, 1054, 0, 0);

Public void showformatdialog () {int RET = SendMessage (Hcapturem, 1065, 0, 0); PUBLIC VOID SavetoDib (String FileName) {int RET = SendMessage (Hcapturem, 1049, 0, FileName);

public void ShowDisplayDialog () {int ret = SendMessage (hCaptureM, 1067, 0, 0);} public System.Drawing.Image getCaptureImage () {System.Windows.Forms.IDataObject iData = System.Windows.Forms.Clipboard.GetDataObject ( ); System.drawing.image retimage = null; if (iData! = Null) {if (iData.GetDataPresent (System.Windows.Forms.DataFormats.bitmap) {retimage = (system.drawing.image) iData.Getdata System.Windows.Forms.DataFormats.Bitmap);} else if (iData.GetDataPresent (System.Windows.Forms.DataFormats.Dib)) {retImage = (System.Drawing.Image) iData.GetData (System.Windows.Forms. DataFormats.dib);}} Return Retimage;} ~ vediocapture () {if (! Isunload) {this.unload ();}}}} To Cnming (cnming) I also use this code to display the effect of the camera, but how to control the size of my actual shooting, others do it in the middle, there is a red frame, I call the getcaptureImage () function, no shooting to the picture Can you write a code when you actually use? Use the cut to store the part you need to store into another file.

Bitmap Sorbmp = New Bitmap ("E: //test.bmp"); Rectangle Rect = New Rectangle (100, 100, 100, 100); Bitmap Clipbmp = New Bitmap (100, 100); // Graphics GS = graphics.FromImage (clipbmp); // GS .Drawimage (sorbmp, rect);

CLIPBMP = Sorbmp.clone (Rect, System.drawing.Imaging.pixelformat.format24bpprgb);

This.PictureBoxResult.Image = clipbmp; sorbmp is a parent, that is, the picture of 640 * 480, there is no need to turn it back.

These two can be written as Rectangle Rect = New Rectangle (XXX, YYY, 240, 180); Bitmap Clipbmp = New Bitmap (240, 180);

XXX, YYY your starting point X and Y coordinates of the starting point of my code: public System.Drawing.Image getCaptureImage () {System.Windows.Forms.IDataObject iData = System.Windows.Forms.Clipboard.GetDataObject (); System.Drawing .Image retimage = null; system.drawing.bitmap bp = null; if (idata! = Null) {if (iData.Windows.Forms.DataFormats.bitmap) {bp = (system.drawing.bitmap) iData.GetData (System.Windows.Forms.DataFormats.Bitmap); Rectangle rect = new Rectangle (0,0,240,180); System.Drawing.Bitmap clipBmp = new Bitmap (240,180); clipBmp = bp.Clone (rect, System.Drawing .Imaging.PixelFormat.Format24bppRgb); retImage = (System.Drawing.Image) clipBmp;} else if (iData.GetDataPresent (System.Windows.Forms.DataFormats.Dib)) {retImage = (System.Drawing.Image) iData. GetData (System.Windows.Forms.DataFormats.dib);}}} still

转载请注明原文地址:https://www.9cbs.com/read-90019.html

New Post(0)