从TCP套接字接收缓冲区的位图显示 [英] Bitmap Display from Buffer received by TCP socket

查看:72
本文介绍了从TCP套接字接收缓冲区的位图显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在窗口上显示我的图像而不保存它。

当收到数据时窗口大小会改变但窗口上没有显示



我的代码是:

I want to display my image on window without saving it.
When data is received window size changes but there is no display
on window.
My Code is:

int iBufferLength;
	int iEnd;
	int iSpaceRemaining;
	
	int i;

	iBufferLength = iSpaceRemaining = sizeof(chIncomingDataBuffer);
	iEnd = 0;
	iSpaceRemaining -= iEnd;

	iBytesRead = recv(Socket, chIncomingDataBuffer+iEnd, iSpaceRemaining, 0);
	
	iEnd+=iBytesRead;
	if (iBytesRead == SOCKET_ERROR)
		MessageBox(hWnd,
						"Socket Error",
						"Connection strt",
						MB_ICONINFORMATION|MB_OK);
		chIncomingDataBuffer[iEnd] = '\0';

	if (lstrlen(chIncomingDataBuffer) != 0)
	{
		/*FILE* pfile;
					
					pfile = 	fopen("test.jpeg", "wb");
				fwrite(chIncomingDataBuffer,1, iBytesRead ,pfile);
				fclose(pfile);*/

				GetWindowRect(hWnd, &rect);
				SetWindowPos(hWnd, NULL, rect.left, rect.top, cBitmap.bmWidth, cBitmap.bmHeight, 0);
				  HDC ThisDC = GetDC(hWnd);

              DeleteDC(RemoteDC);
              RemoteDC = CreateCompatibleDC(ThisDC);
			  DeleteObject(hbitmap);
			  hbitmap= CreateCompatibleBitmap(ThisDC, cBitmap.bmWidth, cBitmap.bmHeight);

			  SelectObject(RemoteDC, hbitmap);

			  ReleaseDC(hWnd, ThisDC);



			  BITMAPINFO bi;
			  HBITMAP hbmap;
			  int bisize = sizeof(BITMAPINFO);
			  memcpy(&bi, chIncomingDataBuffer+iEnd, bisize );
			  SetDIBits(RemoteDC, hbitmap, 0,  cBitmap.bmHeight, chIncomingDataBuffer+iEnd+bisize,  &bi, DIB_RGB_COLORS);


			  InvalidateRect(hWnd, NULL, false);





你能找到我的错误,,,我做错了吗?



Can you find my error,,,where I''m doing wrong?

推荐答案

我没有检查完整的代码。但是来自MSDN GetDIBits()函数的引用显示了一个问题:

I did not check the complete code. But a cite from the MSDN GetDIBits() function shows one problem:
引用:

由hbmp标识的位图当应用程序调用此函数时,不能将参数选择到设备上下文中。

The bitmap identified by the hbmp parameter must not be selected into a device context when the application calls this function.

要查找此类错误,检查可能通过返回值指示错误条件的所有函数的返回值是有帮助的。要将检查限制为调试版本,请使用 ASSERT() VERIFY()宏;例如对于 GetDIBits()函数:

To locate such errors, it is helpful to check the return values of all functions that may indicate error conditions by return value. To limit the check to debug builds, use the ASSERT() and VERIFY() macros; e.g. for the GetDIBits() function:

VERIFY(cBitmap.height == SetDIBits(RemoteDC, hbitmap, 0,  cBitmap.bmHeight, chIncomingDataBuffer+iEnd+bisize, &bi, DIB_RGB_COLORS));


这篇关于从TCP套接字接收缓冲区的位图显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆