跪求C#通过摄像头实现录像并且能录音源程序,顶者有分 在线等

luluyy 2008-12-24 06:48:25
通过摄像头做一个录像的程序逻,还可以录制声音,求源程序~

技术上面的流程也可以说下`~一点头绪也没有` 在网上找了找代码 能录像但不能录音`而且开始录制以后不能关闭~ 不能保存为本地的文件`~ 请教各位大虾帮忙` 不是小弟懒`~ 真是没有头绪`忘高人指点迷津 我一定动手去试试` 先谢谢了~
...全文
921 58 打赏 收藏 转发到动态 举报
写回复
用AI写文章
58 条回复
切换为时间正序
请发表友善的回复…
发表回复
kstg4807394 2012-07-21
  • 打赏
  • 举报
回复
运行时不能拍照怎么办
laomengzi 2010-12-11
  • 打赏
  • 举报
回复
lz视频太大了,如何解决呀??
ggxboy 2010-10-07
  • 打赏
  • 举报
回复
没下文了啊
ygp285369675 2009-12-15
  • 打赏
  • 举报
回复
帮顶,我也想知道
joejan 2009-02-24
  • 打赏
  • 举报
回复
我也想知道答案。
ken_sniper 2008-12-28
  • 打赏
  • 举报
回复
继续帮顶
luluyy 2008-12-27
  • 打赏
  • 举报
回复
别沉啊 麻烦看到的帮顶下` 谢了`
mlhy20060406 2008-12-27
  • 打赏
  • 举报
回复
up
techsky 2008-12-27
  • 打赏
  • 举报
回复
顶顶
luluyy 2008-12-27
  • 打赏
  • 举报
回复
经过大家的指点`看资料 小弟写出来了下面的程序~为了让大家看着方便`把所有的东西都放到form下面了`没有写在类里`

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
using System.IO;

namespace webcam
{
public partial class Form1 : Form
{
private int hHwnd;
private IntPtr lwndC; //保存无符号句柄
public Form1()
{
InitializeComponent();
}

public struct videohdr_tag
{
public byte[] lpData;
public int dwBufferLength;
public int dwBytesUsed;
public int dwTimeCaptured;
public int dwUser;
public int dwFlags;
public int[] dwReserved;

}
public delegate bool CallBack(int hwnd, int lParam);
/// <summary>
/// 必需的设计器变量。
/// </summary>
[DllImport("avicap32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int capCreateCaptureWindowA([MarshalAs(UnmanagedType.VBByRefStr)] ref string lpszWindowName, int dwStyle, int x, int y, int nWidth, short nHeight, int hWndParent, int nID);
[DllImport("avicap32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern bool capGetDriverDescriptionA(short wDriver, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpszName, int cbName, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpszVer, int cbVer);
[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern bool DestroyWindow(int hndw);
[DllImport("user32", EntryPoint = "SendMessageA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int SendMessage(int hwnd, int wMsg, int wParam, [MarshalAs(UnmanagedType.AsAny)] object lParam);
[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int SetWindowPos(int hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
[DllImport("vfw32.dll")]
public static extern string capVideoStreamCallback(int hwnd, videohdr_tag videohdr_tag);
[DllImport("vicap32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern bool capSetCallbackOnFrame(int hwnd, string s);

[DllImport("User32.dll")]
public static extern bool SendMessage(IntPtr hWnd, int wMsg, bool wParam, int lParam);
[DllImport("User32.dll")]
public static extern bool SendMessage(IntPtr hWnd, int wMsg, short wParam, int lParam);

private const int WM_USER = 0x400;
private const int WS_CHILD = 0x40000000;
private const int WS_VISIBLE = 0x10000000;
private const int SWP_NOMOVE = 0x2;
private const int SWP_NOZORDER = 0x4;
private const int WM_CAP_START = WM_USER;
private const int WM_CAP_STOP = WM_CAP_START+68;
private const int WM_CAP_SEQUENCE = WM_CAP_START + 62;
private const int WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20;

/// <summary>
///开始 录制
/// </summary>
/// <param name="path">保存路径</param>
private void StarKinescope(string path)
{
IntPtr hBmp = Marshal.StringToHGlobalAnsi(path);
SendMessage(hHwnd, WM_CAP_FILE_SET_CAPTURE_FILEA, 0, hBmp.ToInt32());
SendMessage(hHwnd, WM_CAP_SEQUENCE, 0, 0);
}
/// <summary>
/// 停止录制
/// </summary>
/// <param name="path"></param>
public void StopKinescope()
{
SendMessage(lwndC, WM_CAP_STOP, 0, 0);
}
private void OpenCapture()
{
try
{
int intWidth = this.panel1.Width;
int intHeight = this.panel1.Height;
int intDevice = 0;
string refDevice = intDevice.ToString();
hHwnd = Form1.capCreateCaptureWindowA(ref refDevice, 1342177280, 0, 0, 640, 480, this.panel1.Handle.ToInt32(), 0);
if (Form1.SendMessage(hHwnd, 0x40a, intDevice, 0) > 0)
{
Form1.SendMessage(this.hHwnd, 0x435, -1, 0);
Form1.SendMessage(this.hHwnd, 0x434, 0x42, 0);
Form1.SendMessage(this.hHwnd, 0x432, -1, 0);
Form1.SetWindowPos(this.hHwnd, 1, 0, 0, intWidth, intHeight, 6);
}
else
{
Form1.DestroyWindow(this.hHwnd);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
//开始录像
private void button1_Click(object sender, EventArgs e)
{
this.button1.Enabled = false;
this.button2.Enabled = true;
this.button3.Enabled = true;
this.OpenCapture();
StarKinescope(@"c:\a.avi");
}
//关闭录像
private void button2_Click(object sender, EventArgs e)
{
this.button1.Enabled = true;
this.button2.Enabled = false;
this.button3.Enabled = false;
Form1.SendMessage(this.hHwnd, 0x40b, 0, 0);
Form1.DestroyWindow(this.hHwnd);
}
//拍照
private void button3_Click(object sender, EventArgs e)
{
try
{
Form1.SendMessage(this.hHwnd, 0x41e, 0, 0);
IDataObject obj1 = Clipboard.GetDataObject();
if (obj1.GetDataPresent(typeof(Bitmap)))
{
Image image1 = (Image)obj1.GetData(typeof(Bitmap));
image1.Save(@"C:\Documents and Settings\Administrator\桌面\aa.bmp");
MessageBox.Show("图像已经保存到桌面");
}
}
catch(Exception ex)
{
MessageBox.Show("截取头像失败,请联系管理员,错误原因为"+ex.ToString());
}
}
private void Form1_Load(object sender, EventArgs e)
{
this.button2.Enabled = false;
this.button3.Enabled = false;
}
}
}


现在遇到的问题是:
1。只能录像`不能录音` 我想要的是录像与录音同时进行` 录完后保存下来`即有录像又有录音像电影一样`
2。压缩问题:现在录制好了以后 只要30秒吧差不多就50M-60M了如果有声音了估计会更大`~

希望大家能给点建议 或参考资料 先谢谢了 上面的代码供大家看看,还望大家能给指点一下~~
wenrenhua08 2008-12-26
  • 打赏
  • 举报
回复
我做过一个不过是用C#做的。
ken_sniper 2008-12-25
  • 打赏
  • 举报
回复
帮顶,这个应该在codeproject网站上有,大多数估计用DX中的DSHOW\DSOUND做的。
lihuyin 2008-12-25
  • 打赏
  • 举报
回复
http://book.csdn.net/bookfiles/499/10049917239.shtml
这上面有代码示例.
uglywolf 2008-12-25
  • 打赏
  • 举报
回复
那个codeproject上有一些源代码,你可以去搜一下
panzi667 2008-12-25
  • 打赏
  • 举报
回复
UP
anncesky 2008-12-25
  • 打赏
  • 举报
回复
以前只用fsm2做过,用c#可能要
niitnanfeng 2008-12-25
  • 打赏
  • 举报
回复
标记下
MadeInTexas 2008-12-25
  • 打赏
  • 举报
回复
关注。。。。
hou881011 2008-12-25
  • 打赏
  • 举报
回复
关注!!!!!!!
周详521 2008-12-25
  • 打赏
  • 举报
回复
study
加载更多回复(38)

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧