视频传输代码
ImageServer.Canvas.Lock;
try
hr := Grabber.SampleGrabber.GetConnectedMediaType(MediaType);
if hr <> S_OK then
Exit;
try
if IsEqualGUID(MediaType.majortype, MEDIATYPE_Video) then
begin
BIHeaderPtr := nil;
if IsEqualGUID(MediaType.formattype, FORMAT_VideoInfo) then
if MediaType.cbFormat = SizeOf(TVideoInfoHeader) then
BIHeaderPtr := @(PVideoInfoHeader(MediaType.pbFormat)^.bmiHeader);
if not Assigned(BIHeaderPtr) then
Exit;
BitmapHandle := CreateDIBSection(0, PBitmapInfo(BIHeaderPtr)^, DIB_RGB_COLORS, DIBPtr, 0, 0);
if BitmapHandle <> 0 then
begin
if DIBPtr = nil then
Exit;
if BufferLen > Integer(BIHeaderPtr^.biSizeImage) then
BufferLen := BIHeaderPtr^.biSizeImage;
Move(pBuffer^, DIBPtr^, BufferLen);
ImageServer.Picture.Bitmap.Handle := BitmapHandle;
end;
end;
finally
FreeMediaType(@MediaType);
end;
memStream := TMemoryStream.Create;
jpg := TJpegImage.Create;
jpg.Assign(ImageServer.Picture.Bitmap);
jpg.CompressionQuality := 100;
jpg.JPEGNeeded;
jpg.Compress;
jpg.SaveToStream(memStream);
jpg.Free;
if TCPClient.Connected then
begin
try
TCPClient.WriteInteger(memStream.Size);
TCPClient.WriteBuffer(memStream.Memory^, memStream.Size, True);
except
end;
end;
memStream.Free;
finally
ImageServer.Canvas.Unlock;
end;