日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C#攝像頭實現(xiàn)拍照功能的簡單代碼示例

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

成都創(chuàng)新互聯(lián)公司是專業(yè)的托里網(wǎng)站建設(shè)公司,托里接單;提供成都網(wǎng)站制作、成都網(wǎng)站設(shè)計,網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進行托里網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!

 
 
 
  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. 這是一個控制攝像頭進行拍照的類,我每次使用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#攝像頭實現(xiàn)拍照功能的簡單代碼示例就介紹到這里。


當(dāng)前文章:C#攝像頭實現(xiàn)拍照功能的簡單代碼示例
文章出自:http://www.dlmjj.cn/article/coiidch.html