Page 1 of 1

BackImage Stream and clear

Posted: Thu Feb 24, 2011 8:33 am
by 10551078
Hello

D2007 and TeeTree VCL 8.04

I load BackImage from Stream, it's Ok that good result with under methode


function LoadBackImageFromStream:Boolean;
Var i:integer;
jpg: TJPEGImage;
Stream1:TMemoryStream;
begin
try
Stream1:=TMemoryStream.Create;
jpg:=TJPEGImage.Create;
try
Stream1:=GetStreamImageFromSever; //Load Stream from my server by Webservice > it's Ok
if Stream1.size>=0 then
jpg.LoadFromStream(Stream1);
Tree1.BackImage.Assign(jpg);

finally
FreeAndNil(jpg);
FreeAndNil(Stream1);
end;
except
//managment error
end;
end;



Q1) do hou have other solution for direct load image by stream, without TJPEGImage and without file disk?

Q2) How do take for clear Image if my stream is empty or bad ?

Q3) do you have best practice and géneral méthode for image (jpeg,bmp,Gif etc) without file disk ?

Re: BackImage Stream and clear

Posted: Thu Feb 24, 2011 11:29 am
by narcis
Hi mivchart,

I think those are Delphi generic issues. I'll give my 2 cents. though.
Q1) do hou have other solution for direct load image by stream, without TJPEGImage and without file disk?
You could use TBitmap as in the code snippet below.

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var Bitmap: TBitmap;
    Stream: TMemoryStream;
begin
  Bitmap:=Bitmap.Create;
  Stream:=TMemoryStream.Create;
  //Load your image to the stream here.

  if Assigned(Stream) then
  begin
    Stream.Position:=0;
    Bitmap.LoadFromStream(Stream);
  end;
end;
Q2) How do take for clear Image if my stream is empty or bad ?
Use Assigned as in the code snippet above.
Q3) do you have best practice and géneral méthode for image (jpeg,bmp,Gif etc) without file disk ?
I don't know if this is best practice but I'd try doing something as in the code example I posted.

Re: BackImage Stream and clear

Posted: Thu Feb 24, 2011 1:47 pm
by 10551078
OK,

But if my Stream used for several type (Jpeg, Gif, Bmp, etc), for each i need déclare spécial grapic type ??

Re: BackImage Stream and clear

Posted: Fri Feb 25, 2011 3:17 pm
by yeray
Hi mivchart,

You could try with TOleGraphic as in the example here.
Also, if you are source code customer, feel free to look into TeeChart sources to see how the different types are treated.