Page 1 of 1

RichViewImportPicture - load Pictures from Web (emails)

Posted: Thu Jul 19, 2018 8:33 am
by josef-b
I want to integrate a own small email-client in our private business application.

So I want to load Pictures from web included in emails I am using THtmViewer and TRVHTMLViewImporter.
procedure TF1.RichViewImportPicture(Sender: TCustomRichView;
const Location: TRVUnicodeString; Width, Height: Integer;
var Graphic: TGraphic);
var Stream: TMemoryStream;
FileStream: TFileStream;
FileName: String;
pic: TPicture;
begin
if (Pos('http://', LowerCase(Location))=1) or
(Pos('https://', LowerCase(Location))=1)
then
begin
Stream := TMemoryStream.Create;
try
// 1. downloading
IdHTTP1.Get(Location, Stream);
// 2. creating temporal file
FileName := GetTempFileName(ExtractFileExt(Location));
FileStream := TFileStream.Create(FileName, fmCreate);
try
FileStream.CopyFrom(Stream, 0);
finally
FileStream.Free;
end;
// 3. reading and deleting temporal file
pic := TPicture.Create;
try
pic.LoadFromFile(FileName);
Graphic := RV_CreateGraphics(TGraphicClass(pic.Graphic.ClassType));
Graphic.Assign(pic.Graphic);
finally
pic.Free;
DeleteFile(FileName);
end;
except
end;

Stream.Free;
end;
Graphic.Free;
Graphic := nil;
end;
It seems it works but after that, there is an error can not load Picture, because it wants to load picture from location "application path + http... again.

Do I not correctly assign graphic/picture..?

Re: RichViewImportPicture - load Pictures from Web (emails)

Posted: Thu Jul 19, 2018 9:15 am
by Sergey Tkachenko
You download picture in Graphics, and then delete this Graphic.
Remove the lines:

Code: Select all

Graphic.Free;
Graphic := nil;

Re: RichViewImportPicture - load Pictures from Web (emails)

Posted: Mon Jul 23, 2018 7:35 am
by josef-b
Thank you that works great now.

I inserted the following because of http error 403:
.....


IDHttp1.Request.Useragent :=
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; MAAU)';
IdHTTP1.Get(Location, Stream);

------