相机将图像捕捉到图像。 想要这张照片在http上可用。 我可以用它以某种方式HTTPServer1CommandGet我显示一个? 我只想在生活上显示image1的图像 如果是这样,怎么样?Delphi indy streaming Http服务器
回答
如果你只需要在客户端需要它来显示最新的图像,你可以做这样的事情:
type
TGetImageStream = class(TIdSync)
protected
FStream: TStream;
procedure DoSynchronize; override;
public
class procedure GetImage(Stream: TStream);
end;
procedure TGetImageStream.DoSynchronize;
begin
Form1.Image1.Bitmap.SaveToStream(FStream);
end;
class procedure TGetImageStream.GetImage(Stream: TStream);
begin
with Create do
try
FStream := Stream;
Synchronize;
finally
Free;
end;
end;
procedure TForm1.HTTPServer1CommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
Strm: TMemoryStream;
begin
Strm := TMemoryStream.Create;
try
TGetImageStream.GetImage(Strm);
Strm.Position := 0;
except
Strm.Free;
raise;
end;
AResponseInfo.ResponseNo := 200;
AResponseInfo.ContentType := 'image/bmp';
AResponseInfo.ContentStream := Strm;
end;
但是,如果你需要做的现场直播相机实时图像,这有点棘手。你可以用几种不同的方法来做到这一点。例如,使用客户端拉:
procedure TForm1.HTTPServer1CommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
Strm: TMemoryStream;
begin
if ARequestInfo.Document = '' then
begin
AResponseInfo.Redirect('/');
end
else if ARequestInfo.Document = '/' then
begin
AResponseInfo.ResponseNo := 200;
AResponseInfo.ContentType := 'text/html';
AResponseIno.ContentText := '<html>'+EOL+
'<head>'+EOL+
'<title>Camera Image</title>'+EOL+
'<meta http-equiv="Refresh" content=5>'+EOL+
'</head>'+EOL+
'<body>'+EOL+
'<img src="/image">'+EOL+
'</body>'+EOL+
'</html>'+EOL;
end
else if ARequestInfo.Document = '/image' then
begin
Strm := TMemoryStream.Create;
try
TGetImageStream.GetImage(Strm);
Strm.Position := 0;
except
Strm.Free;
raise;
end;
AResponseInfo.ResponseNo := 200;
AResponseInfo.ContentType := 'image/bmp';
AResponseInfo.ContentStream := Strm;
end else begin
AResponseInfo.ResponseNo := 404;
end;
end;
使用服务器推送,而不是:
procedure TForm1.HTTPServer1CommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
Strm: TMemoryStream;
begin
Strm := TMemoryStream.Create;
try
AResponseInfo.ResponseNo := 200;
AResponseInfo.ContentType := 'multipart/x-mixed-replace; boundary=imgboundary';
AResponseInfo.CloseConnection := False;
AResponseInfo.WriteHeader;
AContext.Connection.IOHandler.WriteLn('--imgboundary');
repeat
Strm.Clear;
TGetImageStream.GetImage(Strm);
AContext.Connection.IOHandler.WriteLn('Content-type: image/bmp');
AContext.Connection.IOHandler.WriteLn;
AContext.Connection.IOHandler.Write(Strm);
AContext.Connection.IOHandler.WriteLn;
AContext.Connection.IOHandler.WriteLn('--imgboundary');
Sleep(5000);
until False;
finally
Strm.Free;
end;
end;
谢谢! ,你帮了我,我只是编程的初学者,想学习最好的;) – 2014-09-04 09:27:43
作为一个单独的应用程序,以接收此图像到Timage? – 2014-09-05 08:59:50
webbrowser.navigate('localhost');?想要与另一个应用程序,你可以窥视图片 – 2014-09-05 09:00:50
- 1. 正确关闭RemObjects Indy Http服务器
- 2. Delphi XE3,Indy TCP服务器。关闭服务器
- 3. Indy 10 Http服务器示例
- 4. Delphi XE3 indy 10 UDP
- 5. Delphi Indy TCP客户端/服务器通信最佳方法
- 6. Delphi Indy HTTPS从Web服务器检测最新文件
- 7. Delphi indy远程主机UDP客户端/服务器
- 8. HTTP代理服务器中的Delphi DataSap
- 9. Delphi Indy局域网聊天
- 10. Delphi(Indy)特定的锁定
- 11. Delphi indy10 http服务器和ExtJS表单提交
- 12. 检测HTTP服务器使用的HTTP客户端?
- 13. Delphi Streaming Problem
- 14. TIdTCPServer多播(Indy 9 + Delphi 7)
- 15. 印http服务器问题
- 16. 如何在Unix上实现HTTP Live Streaming服务器?
- 17. Delphi(Indy + ADO)CoInitialize Slow
- 18. 使用Indy的代理服务器
- 19. Delphi XE Indy连接到本地服务器API但不是公共服务器API
- 20. 如何安装\在Apache HTTP服务器上启用Adobe HTTP Dynamic Streaming Origin Module?
- 21. Delphi服务器套接字组件
- 22. 在Delphi中的Socket.io服务器XE5
- 23. 将Delphi代码的Indy 10写入C++ Builder的Indy 10
- 24. 使用Delphi 2010和Indy的饼干
- 25. CBuilder中的HTTP服务器
- 26. 在线程中的Delphi(Indy)TIdTCPClient
- 27. Indy TCP服务器不能从服务中运行?
- 28. Delphi 2010 SOAP服务器
- 29. Delphi - Indy - 保存GMail草稿
- 30. Delphi(Indy)线程安全类
道歉,但我绝对不知道你要问什么。首先,你的意思是“将图像捕捉到图像上”? – 2014-09-03 21:51:29
我想在互联网上显示image1的图像帮助http服务器 – 2014-09-03 21:53:44
那么这是一个带有'TImage'控件的VCL表单应用程序吗?我只是在猜测。尽管如此,这只能澄清10%的问题。 – 2014-09-03 21:55:49