-1
我从char *
缓冲区中的服务器接收到一个JPEG图像。我想在保存之前在图片框中显示此图片。我知道的是,图片框可以显示来自File,Hbitmap和Stream的图像。我不想使用这个文件。我不知道如何使用其他的。将char *缓冲区显示为图像
我已经搜索并尝试了一些,这里是我的代码。 我不知道为什么它不显示任何图片。
delegate void setImagedelegate(Stream^image);
void threadDecodeAndShow()
{
while (1)
{
if (f)
{
//the package that is receiving has some custom headers,
// I first find about the size of the JPEG and
//put a pointer at the beginning of the JPEG part.
BYTE *pImgSur = NULL;
DWORD imageInfoLength = *(DWORD*)m_pImgDataBufPtr[nIndexCurBuf];
DWORD customInfoLenForUser = *(DWORD*)(m_pImgDataBufPtr[nIndexCurBuf] + 4 + imageInfoLength);
DWORD jpegLength = *(DWORD*)(m_pImgDataBufPtr[nIndexCurBuf] + 4 + imageInfoLength + 4 + customInfoLenForUser);
pImgSur = (BYTE *)(m_pImgDataBufPtr[nIndexCurBuf] + 12 + customInfoLenForUser + imageInfoLength);
auto store = gcnew array<Byte>(jpegLength);
System::Runtime::InteropServices::Marshal::Copy(IntPtr(pImgSur), store, 0, jpegLength);
auto stream = gcnew System::IO::MemoryStream(store);
this->setImage(stream);
f = 0;
}
}
}
void setImage(Stream^image)
{
if (this->pictureBox1->InvokeRequired)
{
setImagedelegate^ d =
gcnew setImagedelegate(this, &MainPage::setImage);
this->Invoke(d, gcnew array<Object^> { image });
}
else
{
this->pictureBox1->Image = Image::FromStream(image);
this->pictureBox1->Show();
}
}
谢谢你的回答,尝试了很多东西后,你的解决方案没有错误地工作,但它不显示任何图像。 – Eoaneh
嗯,这段代码不应该“显示任何图像”,它只是转换字节。我不可能猜到,你必须提出另一个问题,并正确记录你对返回的Image对象做了什么。 –
我编辑了我的帖子并添加了代码。你可以请看看吗? – Eoaneh