Problem with FromStream in PictureBox

  • Thread starter Thread starter XpyXt
  • Start date Start date
X

XpyXt

Guest
Hi again!!!

I am using Visual C++/CLI
I have a picture in a buffer and i need put it in picturebox. The error give me is: Invalid parameter in the source code Image ^Ima = Drawing::Image::FromStream(asd); // asd is a stream.




Code Snippet

MemoryStream ^streamMem = gcnew MemoryStream;
StreamReader ^PrivateStreamW = gcnew StreamReader(sysWsk->DebugSR());

array<unsigned char>^ImaArray = gcnew array<unsigned char>(6866);
while( PrivateStreamW->Peek() >= 0)
{
ImaArray[Size] = /*(Char)*/PrivateStreamW->Read();
Size++;
}
Debug::WriteLine("Size Sector " + Size.ToString());

streamMem->Write(ImaArray,0,6866);
Stream ^asd = streamMem;
Image ^Ima = Drawing::Image::FromStream(asd); // <- CRASH
// or Image ^Ima = Drawing::Image::FromStream(streamMem); // <- CRASH
pictureBox1->Image = Ima;



Any idea?


I Have other source and this work it, and i see image in picturebox.


Code Snippet

Form1 ^Ob = (Form1^) Obj;
Debug::WriteLine("Escuchando...");
Socket ^tcpListen = gcnew Socket(AddressFamily::InterNetwork,SocketType::Stream,ProtocolType::Tcp);
IPEndPoint ^iped = gcnew IPEndPoint(IPAddress::Any,666);
tcpListen->Bind(iped);
tcpListen->Listen(0);
Socket ^AcceptSck = tcpListen->Accept();
array<unsigned char>^msg = gcnew array<unsigned char>(3932214);
int rcv = AcceptSck->Receive(msg,3932214,SocketFlags::None);
MemoryStream ^a = gcnew MemoryStream;
a->Write(msg,0,rcv);
Debug::WriteLine("Size: " + rcv.ToString());
Image ^ima = Drawing::Image::FromStream(a);
Ob->pictureBox1->Image = ima;

Continue reading...
 
Back
Top