RichViewImportPicture - load Pictures from Web (emails)

General TRichView support forum. Please post your questions here
Post Reply
josef-b
Posts: 5
Joined: Sun Mar 15, 2015 4:45 pm

RichViewImportPicture - load Pictures from Web (emails)

Post by josef-b » Thu Jul 19, 2018 8:33 am

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..?

Sergey Tkachenko
Site Admin
Posts: 14166
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: RichViewImportPicture - load Pictures from Web (emails)

Post by Sergey Tkachenko » Thu Jul 19, 2018 9:15 am

You download picture in Graphics, and then delete this Graphic.
Remove the lines:

Code: Select all

Graphic.Free;
Graphic := nil;

josef-b
Posts: 5
Joined: Sun Mar 15, 2015 4:45 pm

Re: RichViewImportPicture - load Pictures from Web (emails)

Post by josef-b » Mon Jul 23, 2018 7:35 am

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);

------

Post Reply