DELPHI使用IDHTTP显示网络图片
来源:互联网 发布:知乎怎么增加 编辑:程序博客网 时间:2024/06/05 02:58
DELPHI使用IDHTTP显示网络图片:
程序代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, IdBaseComponent, IdComponent,
GifImage, Jpeg, IdTCPConnection, IdTCPClient, IdHTTP;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Image1: TImage;
IdHTTP1: TIdHTTP;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
imagestream:TMemoryStream;
Buffer:Word;
jpg:TjpegImage;
gif:TgifImage;
begin
image1.Picture.Graphic:=nil ;
imagestream := TMemoryStream.Create();
try
IdHTTP1.Request.Accept := '*/*';
IdHTTP1.Request.AcceptLanguage := 'zh-cn';
IdHTTP1.Request.UserAgent:='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)';
IdHTTP1.Request.Connection := 'Keep-Alive';
IdHTTP1.HTTPOptions:=IdHTTP1.HTTPOptions+[hoKeepOrigProtocol];
IdHTTP1.ProtocolVersion:=pv1_1;
try
idhttp1.Get(Edit1.Text,imagestream);
except
showmessage('连接失败!');
exit;
end;
imagestream.Position:=0;
if imagestream.Size = 0 then
begin
imagestream.Free;
ShowMessage('错误!');
exit;
end;
imagestream.ReadBuffer(Buffer,2);
imagestream.Position:=0;
if Buffer=$4D42 then //bmp
begin
image1.Picture.Bitmap.LoadFromStream(imagestream);
end
else if Buffer=$D8FF then //jpg
begin
jpg:=TjpegImage.Create;
jpg.LoadFromStream(imagestream);
image1.Picture.Assign(jpg);
jpg.Free;
end
else if Buffer=$4947 then //gif
begin
gif:=TGifImage.Create;
gif.LoadFromStream(imagestream);
image1.Picture.Assign(gif);
gif.Free;
end
else if Buffer=$050A then
begin
ShowMessage('PCX');
end
else if Buffer=$5089 then
begin
ShowMessage('PNG');
end
else if Buffer=$4238 then
begin
ShowMessage('PSD');
end
else if Buffer=$A659 then
begin
ShowMessage('RAS');
end
else if Buffer=$DA01 then
begin
ShowMessage('SGI');
end
else if Buffer=$4949 then
begin
ShowMessage('TIFF');
end
else
begin
ShowMessage('ERROR');
end;
finally
imagestream.Free;
end;
end;
end.
- DELPHI使用IDHTTP显示网络图片
- delphi idhttp使用
- Delphi 使用idhttp下載显示进度以及大小
- Delphi 使用idhttp下載显示进度以及大小
- Delphi 使用idhttp下載显示进度以及大小
- DELPHI使用IDHTTP操作WEB
- delphi使用IdHTTP模拟提交页面方法
- Delphi使用IdHttp 获取 HttpsURL内容
- [Delphi]IDHTTP 获取URL网络异常返回报文
- 使用ListView显示网络图片
- 使用SimpleAdapter显示网络图片
- delphi使用IdHTTP模拟提交页面方法总结
- Delphi中强制IdHTTP使用HTTP1.1(转)
- delphi 7中使用idhttp抓取网页 解决假死现象
- delphi的idhttp的get 和 post的使用
- delphi的idhttp的get 和 post的使用
- delphi的idhttp的get 和 post的使用
- delphi使用IdHTTP模拟提交页面方法总结
- Problem D: 链表的基本运算(线性表)
- Android中Activity转场
- 解决虚拟机中无法访问USB串口设备问题
- 数据结构学习笔记(二)多项式加法与乘法
- 博通wifi驱动
- DELPHI使用IDHTTP显示网络图片
- ardupilot的libraries之PID
- KSImageNamed-Xcode-master 实用Xcode插件
- 1016 of greedy strategy
- 浅谈Android Fragment
- 每天一篇python:函数篇
- Community Detection (社区发现)算法
- jsp继续学习
- Less学习