.net - Stream to Byte array conversion in Oxygene -


i'm trying find way out legacy delphi prism application. have never worked on delphi prism before.

how convert stream type byte array type? please detailed code appreciated have no knowledge of delphi prism.

basically want upload image using wcf service , want pass image data byte array.

thanks.

option 1) if using memorystream can use memorystream.toarray method directly.

option 2) if using .net 4, copy content of source stream using copyto method memorystream , call memorystream.toarray function.

like so

method tmyclass.streamtobytearr(astream: stream): array of byte; begin     using lstream: memorystream := new memorystream()      begin       astream.copyto(lstream);       exit(lstream.toarray());     end end; 

option 3) using old verison of .net, can write custom function extract data source stream , fill memorystream

method tmyclass.streamtobytearr(astream: stream): array of byte; var    lbuffer: array of system.byte;   rbytes: system.int32:=0; begin   lbuffer:=new system.byte[1024];   using lstream: memorystream := new memorystream()    begin     while true      begin       rbytes := astream.read(lbuffer, 0, lbuffer.length);       if rbytes>0         lstream.write(lbuffer, 0, rbytes)       else         break;     end;     exit(lstream.toarray());    end; end; 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -