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 »

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: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: RichViewImportPicture - load Pictures from Web (emails)

Post by Sergey Tkachenko »

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 »

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