No. because MyIEBitmap.VclBitmap is a TBitmap regardless of the file type that is loaded. Although Nigel pointed out that you may not be able to assign a TBitmap to TGraphic, but you could also try to assign to TPicture or TBitmap. TBitmap will work for sure.
Here is some tested code:
function DownloadUrl(AUrl: string): TBitmap;
{ Download a bitmap from a url. }
var
iIEBitmap: TieBitmap;
begin
iIEBitmap := TieBitmap.Create;
try
if iIEBitmap.LoadFromURL(AUrl, '', '', '') then
begin
{ Resample the TIEBitmap to 50% }
iIEBitmap.Resample(iIEBitmap.Width div 2, -1, rfNone);
Result := TBitmap.Create;
iIEBitmap.CopyToTBitmap(Result);
end
else
MessageBox(0, 'Error downloading image.', 'Warning',
MB_ICONWARNING or MB_OK);
finally
iIEBitmap.Free;
end;
end;
procedure TForm1.DownloadClick(Sender: TObject);
{ Download a bitmap from a url and assign the bitmap to TImageEnView. }
var
iBitmap: TBitmap;
begin
Screen.Cursor := crHourGlass;
try
iBitmap := TBitmap.Create;
try
iBitmap := DownloadUrl(Url1.Text);
ImageEnView1.IEBitmap.Assign(iBitmap);
ImageEnView1.Update;
finally
iBitmap.Free;
end;
finally
Screen.Cursor := crDefault;
end;
end;
If you really need a TGraphic use a TPicture instead.
When the type of graphic is known, store the graphic in its specific type object. Otherwise, use a TPicture object that can hold any type of TGraphic:
function DownloadUrl2(AUrl: string): TPicture;
{ Download a TPicture from a url. }
var
iIEBitmap: TieBitmap;
begin
iIEBitmap := TieBitmap.Create;
try
{ Load an image from a url }
if iIEBitmap.LoadFromURL(AUrl, '', '', '') then
begin
{ Resample the TIEBitmap to 50% }
iIEBitmap.Resample(iIEBitmap.Width div 2, -1, rfNone);
Result := TPicture.Create;
{ Copy the TIEBitmap to TBitmap }
iIEBitmap.CopyToTBitmap(Result.Bitmap);
end
else
MessageBox(0, 'Error downloading image.', 'Warning',
MB_ICONWARNING or MB_OK);
finally
iIEBitmap.Free;
end;
end;
procedure TForm1.DownloadClick(Sender: TObject);
{ Download a picture from a url and assign the bitmap to TImageEnView. }
var
iPicture: TPicture;
begin
Screen.Cursor := crHourGlass;
try
iPicture := TPicture.Create;
try
{ Get the TPicture }
iPicture := DownloadUrl2(Url1.Text);
{ Display the picture }
ImageEnView1.IEBitmap.Assign(iPicture.Bitmap);
ImageEnView1.Update;
finally
iPicture.Free;
end;
finally
Screen.Cursor := crDefault;
end;
end;
Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development