"steve blake" <steb...@hotmail.com> wrote in message
news:3dcd2c2f$1...@newsgroups.borland.com...
> Being a Dilbert fan, I was glad to find a webservice which lets me:
> 1: Get a path of a daily Dilbert gif file. (function
DailyDilbertImagePath:
> WideString; stdcall;)
> 2: Get the actual image as TByteDynArray (function DailyDilbertImage:
> TByteDynArray; stdcall;)
> I created a unit the standard way in D7E by importing the wsdl
> http://www.esynaps.com/WebServices/DailyDiblert.asmx?WSDL
> In the interface, the first function's result is a Widestring, so that's
no
> problem, it simply returns a path, like
>
http://www.dilbert.com/comics/dilbert/archive/images/dilbert2002111108309.gi
> f
> But what I would like to do is to show the image directly in my
application.
> My approach was to use a TImage, and then the Picture property. My graphic
> programming skill is poor, so I would appreciate help on this issue.
> My approach in the code was something like:
> ...
> var
> i: Integer;
> ba: TByteDynArray; //Actually array of byte
> begin
> ba := GetDailyDilbertSoap.DailyDilbertImage;
> MyLabel.Caption := IntToStr(Length(ba)); //returns a value of about
15000
> ... to be continued
>
> But how do I get this array of bytes into an image???
Well, it is a few years since I last programmed graphics, but I think you
should do the following:
Look for TGifImage on google/Jedi.
Move the Bytearray into a stream, and look for .loadfromstream method in
TgifImage.
You may get further assistance in the .graphics group.
--
Med venlig hilsen/Best regards
Stig Johansen
Stig.J...@udvikling.it.dk
(remove dot dk)
"Stig Johansen" <stig.j...@udvikling.it> wrote in message
news:3dcd...@newsgroups.borland.com...
> Hi.
"steve blake" <steb...@hotmail.com> wrote in message
news:3dcec72a$1...@newsgroups.borland.com...
> Hi Stig,
> I will download that component. Actually I thought that I could use
> MyImage.Picture.Bitmap.LoadFromStream(MyStream).
> The problem is I do not know how to move the data from the bytearray to
the
> stream.
> Any idea?
Try somthing like
MyStream.WriteBuffer(ba[0],Length(ba));
I have a few functions for this:
function ByteArrayFromStream( inStream : TMemoryStream ) : TByteDynArray;
procedure ByteArrayToFIle( const ByteArray : TByteDynArray;
const FileName : string );
function FIleToByteArray( const FileName : string ) : TByteDynArray;
procedure CopyToStream( const InArray : TByteDynArray ; outStream :
TStream );
implementation
uses Math;
procedure ByteArrayToFIle( const ByteArray : TByteDynArray;
const FileName : string );
var Count : integer;
F : FIle of Byte;
pTemp : Pointer;
begin
AssignFile( F, FileName );
Rewrite(F);
try
Count := Length( ByteArray );
pTemp := @ByteArray[0];
BlockWrite(F, pTemp^, Count );
finally
CloseFile( F );
end;
end;
function FIleToByteArray( const FileName : string ) : TByteDynArray;
const BLOCK_SIZE=1024;
var BytesRead, BytesToWrite, Count : integer;
F : FIle of Byte;
pTemp : Pointer;
begin
AssignFile( F, FileName );
Reset(F);
try
Count := FileSize( F );
SetLength(Result, Count );
pTemp := @Result[0];
BytesRead := BLOCK_SIZE;
while (BytesRead = BLOCK_SIZE ) do
begin
BytesToWrite := Min(Count, BLOCK_SIZE);
BlockRead(F, pTemp^, BytesToWrite , BytesRead );
pTemp := Pointer(LongInt(pTemp) + BLOCK_SIZE);
Count := Count-BytesRead;
end;
finally
CloseFile( F );
end;
end;
function ByteArrayFromStream( inStream : TMemoryStream ) : TByteDynArray;
var pTemp : pointer;
begin
SetLength(Result, inStream.Size );
pTemp := @Result[0];
inStream.Position := 0;
inStream.Read(pTemp^, inStream.Size);
end;
procedure CopyToStream( const InArray : TByteDynArray ; outStream :
TStream );
var pTemp : Pointer;
begin
pTemp := @InArray[0];
outStream.Write( pTemp^, Length(InArray));
end;
end.
[Ok, I know, terrible names]
--
Deepak Shenoy (TeamB)
Agni Software
http://www.agnisoft.com
"Deepak Shenoy (TeamB)" <sheno...@SOMETEXTagnisoft.com> wrote in message
news:3dcf...@newsgroups.borland.com...