成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

C#攝像頭實(shí)現(xiàn)拍照功能的簡單代碼示例

開發(fā) 后端
這里將介紹一個C#攝像頭實(shí)現(xiàn)拍照功能的簡單代碼示例,代碼雖然不短,但是基本上實(shí)現(xiàn)了相對應(yīng)的功能,希望對大家有所幫助。

C#攝像頭實(shí)現(xiàn)拍照功能的簡單代碼示例

  1. using System;  
  2. using System.Runtime.InteropServices;  
  3. using System.Drawing;  
  4. using System.Drawing.Imaging;  
  5. namespace Video  
  6. {  
  7. ///   
  8. /// 一個C#攝像頭控制類  
  9. /// 
  10.  
  11. public class VideoWork  
  12. {  
  13. private const int WM_USER = 0x400;  
  14. private const int WS_CHILD = 0x40000000;  
  15. private const int WS_VISIBLE = 0x10000000;  
  16. private const int WM_CAP_START = WM_USER;  
  17. private const int WM_CAP_STOP = WM_CAP_START + 68;  
  18. private const int WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10;  
  19. private const int WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11;  
  20. private const int WM_CAP_SAVEDIB = WM_CAP_START + 25;  
  21. private const int WM_CAP_GRAB_FRAME = WM_CAP_START + 60;  
  22. private const int WM_CAP_SEQUENCE = WM_CAP_START + 62;  
  23. private const int WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20;  
  24. private const int WM_CAP_SEQUENCE_NOFILE =WM_CAP_START+ 63;  
  25. private const int WM_CAP_SET_OVERLAY =WM_CAP_START+ 51;   
  26. private const int WM_CAP_SET_PREVIEW =WM_CAP_START+ 50;   
  27. private const int WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START +6;  
  28. private const int WM_CAP_SET_CALLBACK_ERROR=WM_CAP_START +2;  
  29. private const int WM_CAP_SET_CALLBACK_STATUSA= WM_CAP_START +3;  
  30. private const int WM_CAP_SET_CALLBACK_FRAME= WM_CAP_START +5;  
  31. private const int WM_CAP_SET_SCALE=WM_CAP_START+ 53;  
  32. private const int WM_CAP_SET_PREVIEWRATE=WM_CAP_START+ 52;   
  33. private IntPtr hWndC;  
  34. private bool bWorkStart = false;  
  35. private IntPtr mControlPtr;  
  36. private int mWidth;  
  37. private int mHeight;  
  38. private int mLeft;  
  39. private int mTop;  
  40.  
  41. ///   
  42. /// 初始化顯示圖像  
  43. /// 
  44.  
  45. /// 控件的句柄  
  46. /// 開始顯示的左邊距  
  47. /// 開始顯示的上邊距  
  48. /// 要顯示的寬度  
  49. /// 要顯示的長度  
  50. public VideoWork(IntPtr handle, int left, int top, int width,int height)  
  51. {  
  52. mControlPtr = handle;  
  53. mWidth = width;  
  54. mHeight = height;  
  55. mLeft = left;  
  56. mTop = top;  
  57. }  
  58. [DllImport("avicap32.dll")]   
  59. private static extern IntPtr capCreateCaptureWindowA(byte[] lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, int nID);  
  60. [DllImport("avicap32.dll")]  
  61. private static extern int capGetVideoFormat(IntPtr hWnd, IntPtr psVideoFormat, int wSize );  
  62. [DllImport("User32.dll")]   
  63. private static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, long lParam);  
  64. ///   
  65. /// 開始顯示圖像  
  66. /// 
  67.  
  68. public void Start()  
  69. {  
  70. if (bWorkStart)  
  71. return;  
  72. bWorkStart = true;  
  73. byte[] lpszName = new byte[100];  
  74. hWndC = capCreateCaptureWindowA(lpszName,WS_CHILD|WS_VISIBLE ,mLeft,mTop,mWidth,mHeight,mControlPtr,0);  
  75. if (hWndC.ToInt32() != 0)  
  76. {  
  77. SendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);  
  78. SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0);  
  79. SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0);  
  80. SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0);  
  81. SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0);  
  82. SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0);  
  83. SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0);  
  84. SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0);  
  85. //Global.log.Write("SendMessage");  
  86. }  
  87. return;  
  88. }  
  89. ///   
  90. /// 停止顯示  
  91. /// 
  92.  
  93. public void Stop()  
  94. {  
  95. SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0);  
  96. bWorkStart = false;  
  97. }  
  98. ///   
  99. /// 抓圖  
  100. /// 
  101.  
  102. /// 要保存bmp文件的路徑  
  103. public void GrabImage(string path)  
  104. {  
  105. IntPtr hBmp = Marshal.StringToHGlobalAnsi(path);  
  106. SendMessage(hWndC,WM_CAP_SAVEDIB,0,hBmp.ToInt64());  
  107. }  
  108. }  
  109. }  
  110.    
  111. 這是一個控制攝像頭進(jìn)行拍照的類,我每次使用GrabImage抓圖都是225K的一張照片,我想請問如何才能讓我抓到的圖片小一些,我想控制在70K左右。不知怎么讓拍照的像素變小?  
  112.    
  113. if(this.Request.QueryString["filename"]!=null)  
  114. {  
  115.                 //獲取原圖片  
  116. string filename=this.Request.QueryString["filename"];  
  117. Bitmap bmpOld=new Bitmap(this.Server.MapPath("images/" + filename));  
  118.     //計算縮小比例  
  119. double d1;  
  120. if(bmpOld.Height>bmpOld.Width)  
  121. d1=(double)(MaxLength/(double)bmpOld.Width);  
  122. else 
  123. d1=(double)(MaxLength/(double)bmpOld.Height);  
  124. //產(chǎn)生縮圖  
  125. Bitmap bmpThumb=new Bitmap(bmpOld,(int)(bmpOld.Width*d1),(int)(bmpOld.Height*d1));  
  126. //清除緩沖  
  127. Response.Clear();  
  128. //生成圖片  
  129. bmpThumb.Save(this.Response.OutputStream,ImageFormat.Jpeg);  
  130. Response.End();  
  131. //釋放資源  
  132. bmpThumb.Dispose();  
  133. bmpOld.Dispose();  

C#攝像頭實(shí)現(xiàn)拍照功能的簡單代碼示例就介紹到這里。

【編輯推薦】

  1. C#服務(wù)端與客戶端連接實(shí)現(xiàn)淺析
  2. C#服務(wù)端與客戶端連接實(shí)現(xiàn)淺談
  3. C#服務(wù)端與客戶端通信淺析
  4. C#服務(wù)端與客戶端通信詳解
  5. C#服務(wù)端程序?qū)崿F(xiàn)同步傳輸字符串淺析
責(zé)任編輯:彭凡 來源: 51CTO
相關(guān)推薦

2009-08-21 17:55:14

C#獲取攝像頭

2009-08-21 17:17:49

C#攝像頭編程

2009-08-21 17:24:18

C#控制攝像頭

2016-02-22 10:30:38

AngularJSHTML5攝像頭

2023-02-26 22:06:22

Electron瀏覽器開發(fā)

2009-09-08 09:31:54

c# CheckBox

2023-09-14 10:05:33

人工智能智能攝像頭

2022-04-15 11:30:59

代碼,Python保存視頻

2025-01-13 00:00:30

WinForm應(yīng)用開發(fā)

2021-03-11 10:21:55

特斯拉黑客網(wǎng)絡(luò)攻擊

2017-06-20 11:45:52

2013-03-21 09:56:09

2009-08-27 18:05:54

C#索引功能

2009-08-06 10:55:46

C#代碼解釋器

2024-11-29 16:51:18

2011-04-25 09:16:10

Windows 8

2012-06-23 20:13:44

HTML5

2009-08-13 10:15:50

C#讀取Excel

2009-09-07 15:27:04

C# MessageB

2009-08-13 17:36:54

編譯C#代碼
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 伊人网综合 | 精品综合 | 高清亚洲 | 天天色天天射天天干 | 免费久久精品视频 | 久久精品免费看 | 国产精品日韩一区二区 | 亚洲一区二区av | 午夜欧美日韩 | 91精品国产91久久久 | 羞羞免费网站 | 国产高清在线精品 | 99福利视频 | 国产综合久久 | 91大神xh98xh系列全部 | 国产综合欧美 | 久久毛片网站 | 亚洲三级在线 | 狠狠狠干| 精品一区久久 | 在线视频成人 | 亚洲午夜在线 | 亚洲成人中文字幕 | 日韩亚洲欧美综合 | 永久看片 | 成人在线免费观看视频 | 99久久久国产精品免费消防器 | 中文字幕一区在线观看视频 | 国产精品a久久久久 | 国产精品九九九 | 一区二区免费在线 | 丁香五月网久久综合 | 亚洲精品久久久久中文字幕二区 | 黄色国产在线播放 | 91久久电影 | 成人性视频免费网站 | 美日韩一区二区 | 成人做爰999 | 99精品网站 | 国产在线a视频 | 亚洲欧美日韩一区 |