[C#] Webcam entre PC

cs_piep14 Messages postés 345 Date d'inscription lundi 15 mars 2004 Statut Membre Dernière intervention 13 mai 2011 - 23 juin 2005 à 15:59
aogie Messages postés 108 Date d'inscription vendredi 11 juillet 2003 Statut Membre Dernière intervention 27 novembre 2007 - 23 juin 2005 à 21:34
Bonjour tout le monde. J'ai une ptit question pour le projet d'un ami.


On a deux PC équipés chacun d'un WebCam et un site internet.


On aimerait que l'on puisse afficher l'un et l'autre la webcam de la personne distante !!!


J'espère mettre fait comprendre.


Je souhaite voir en faite sa webcam et lui la mienne. Auriez vous un bon tutos pour faire ceci, ou des pistes pour qu'un se lance.


Merci sincèrement de votre aide.

2 réponses

cs_piep14 Messages postés 345 Date d'inscription lundi 15 mars 2004 Statut Membre Dernière intervention 13 mai 2011
23 juin 2005 à 18:51
Voici le code que je viens de trouver en delphi et qui affiche bien ma webcam.






Code:, ----
unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls,clipbrd, ExtCtrls;

type

TForm1 = class(TForm)

Image1: TImage;

Timer1: TTimer;

procedure FormCreate(Sender: TObject);

procedure Timer1Timer(Sender: TObject);

private

{ Déclarations privées }

public

{ Déclarations publiques }

end;

var

Form1: TForm1;

HCam:hwnd;

bmp:tbitmap;

Function capCreateCaptureWindowA(lpszWindowName : String; dwStyle :
integer; X : integer; Y : integer; nWidth : integer; nHeight :
integer; hwndParent : hwnd; nID : integer):integer; stdcall; external
'C:\windows\system32\avicap32.dll';

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);

begin

bmp:=tbitmap.Create;

bmp.Width:=320;

bmp.Height:=240;

image1.Width:=320;

image1.Height:=240;

//Handle du periph d ela cam

hcam:=capCreateCaptureWindowA('',0,0,0,320,240,handle,0);

//Connection a la cam

sendmessage(hcam,1034,0,0);

form1.DoubleBuffered:=true;

end;

procedure TForm1.Timer1Timer(Sender: TObject);

begin

//Capture d'image de la cam

sendmessage(hcam,1084,0,0);

//Copie dna sle presse papier de l'image

sendmessage(hcam,1054,0,0);

image1.Picture.LoadFromClipboardFormat(cf_bitmap,clipboard.GetAsHandle(cf_bitmap),0);

bmp.Canvas.Draw(0,0,image1.Picture.Bitmap);

end;

end.






Si vous savez comment je peux le convertir en Csharp, je suis
preneur.

Merci
0
aogie Messages postés 108 Date d'inscription vendredi 11 juillet 2003 Statut Membre Dernière intervention 27 novembre 2007
23 juin 2005 à 21:34
Bonsoir,

Pour capCreateCaptureWindow :

[DllImport("avicap32.dll", CharSet=CharSet.Auto)]

private
static
extern IntPtr capCreateCaptureWindow(

string lpszWindowName,

int dwStyle,

int x,

int y,

int nWidth,

int nHeight,
IntPtr hwndParent,

int nID);

Concernant les différents messages :

#region enums privés avicap32.dll



public
enum eAvicapMessage :
int
{
WM_CAP_START = 0x400,
WM_CAP_SET_CALLBACK_ERROR = (WM_CAP_START + 2),
WM_CAP_SET_CALLBACK_STATUS = (WM_CAP_START + 3),
WM_CAP_SET_CALLBACK_YIELD = (WM_CAP_START + 4),
WM_CAP_SET_CALLBACK_FRAME = (WM_CAP_START + 5),
WM_CAP_SET_CALLBACK_VIDEOSTREAM = (WM_CAP_START + 6),
WM_CAP_SET_CALLBACK_WAVESTREAM = (WM_CAP_START + 7),
WM_CAP_GET_USER_DATA = (WM_CAP_START + 8),
WM_CAP_SET_USER_DATA = (WM_CAP_START + 9),
WM_CAP_DRIVER_CONNECT = (WM_CAP_START + 10),
WM_CAP_DRIVER_DISCONNECT = (WM_CAP_START + 11),
WM_CAP_DRIVER_GET_NAME = (WM_CAP_START + 12),
WM_CAP_DRIVER_GET_VERSION = (WM_CAP_START + 13),
WM_CAP_DRIVER_GET_CAPS = (WM_CAP_START + 14),
WM_CAP_FILE_SET_CAPTURE_FILE = (WM_CAP_START + 20),
WM_CAP_FILE_GET_CAPTURE_FILE = (WM_CAP_START + 21),
WM_CAP_FILE_SAVEAS = (WM_CAP_START + 23),
WM_CAP_FILE_SAVEDIB = (WM_CAP_START + 25),
WM_CAP_FILE_ALLOCATE = (WM_CAP_START + 22),
WM_CAP_FILE_SET_INFOCHUNK = (WM_CAP_START + 24),
WM_CAP_EDIT_COPY = (WM_CAP_START + 30),
WM_CAP_SET_AUDIOFORMAT = (WM_CAP_START + 35),
WM_CAP_GET_AUDIOFORMAT = (WM_CAP_START + 36),
WM_CAP_DLG_VIDEOFORMAT = (WM_CAP_START + 41),
WM_CAP_DLG_VIDEOSOURCE = (WM_CAP_START + 42),
WM_CAP_DLG_VIDEODISPLAY = (WM_CAP_START + 43),
WM_CAP_GET_VIDEOFORMAT = (WM_CAP_START + 44),
WM_CAP_SET_VIDEOFORMAT = (WM_CAP_START + 45),
WM_CAP_DLG_VIDEOCOMPRESSION = (WM_CAP_START + 46),
WM_CAP_SET_PREVIEW = (WM_CAP_START + 50),
WM_CAP_SET_OVERLAY = (WM_CAP_START + 51),
WM_CAP_SET_PREVIEWRATE = (WM_CAP_START + 52),
WM_CAP_SET_SCALE = (WM_CAP_START + 53),
WM_CAP_GET_STATUS = (WM_CAP_START + 54),
WM_CAP_SET_SCROLL = (WM_CAP_START + 55),
WM_CAP_GRAB_FRAME = (WM_CAP_START + 60),
WM_CAP_GRAB_FRAME_NOSTOP = (WM_CAP_START + 61),
WM_CAP_SEQUENCE = (WM_CAP_START + 62),
WM_CAP_SEQUENCE_NOFILE = (WM_CAP_START + 63),
WM_CAP_SET_SEQUENCE_SETUP = (WM_CAP_START + 64),
WM_CAP_GET_SEQUENCE_SETUP = (WM_CAP_START + 65),
WM_CAP_SET_MCI_DEVICE = (WM_CAP_START + 66),
WM_CAP_GET_MCI_DEVICE = (WM_CAP_START + 67),
WM_CAP_STOP = (WM_CAP_START + 68),
WM_CAP_ABORT = (WM_CAP_START + 69),
WM_CAP_SINGLE_FRAME_OPEN = (WM_CAP_START + 70),
WM_CAP_SINGLE_FRAME_CLOSE = (WM_CAP_START + 71),
WM_CAP_SINGLE_FRAME = (WM_CAP_START + 72),
WM_CAP_PAL_OPEN = (WM_CAP_START + 80),
WM_CAP_PAL_SAVE = (WM_CAP_START + 81),
WM_CAP_PAL_PASTE = (WM_CAP_START + 82),
WM_CAP_PAL_AUTOCREATE = (WM_CAP_START + 83),
WM_CAP_PAL_MANUALCREATE = (WM_CAP_START + 84),

// Following added post VFW 1.1
WM_CAP_SET_CALLBACK_CAPCONTROL = (WM_CAP_START + 85),
WM_CAP_END = (WM_CAP_START + 181)
}

#endregion

Connexion au Driver :

bool bRetval = (SendMessage(
_hwnd, //handle de fenêtre de capture
eAvicapMessage.WM_CAP_DRIVER_CONNECT,
index, //index du driver à utiliser consulter éventuellement le drivers disponibles à l'aide de capGetDriverDescription (index de 0 à 9).

0) != 0
);

avec l'API SendMessage :

[DllImport("user32.dll", CharSet=CharSet.Auto)]

private
static
extern
int SendMessage(
IntPtr hWnd,
Avicap.eAvicapMessage msg,

int wParam,

int lParam
);

Ensuite on capture une image :


bool bRetVal = (SendMessage(
_hwnd,
eAvicapMessage.WM_CAP_GRAB_FRAME_NOSTOP, //sans interruption Preview
0,
0) != 0
);

ou

bool bRetVal = (SendMessage(
_hwnd,
eAvicapMessage.WM_CAP_GRAB_FRAME, //avec interruption Preview
0,
0) != 0
);

Copie vers le presse-papiers :

bool bRetVal = (SendMessage(
_hwnd,
eAvicapMessage.WM_CAP_EDIT_COPY,
0) != 0
);

Chargement image du presse-papiers :

/// <summary>
/// Retourne la représentation Bitmap d'un objet du presse-papiers.
/// </summary>
/// <returns>Image Bitmap (si le format existe ou null).</returns>
public
static Bitmap GetBitmapFrame()
{
IDataObject iData = Clipboard.GetDataObject();

if (!iData.GetDataPresent(DataFormats.Bitmap))
return
null;

return (Bitmap)iData.GetData(DataFormats.Bitmap);
}

-- AOGie --
0
Rejoignez-nous