locked
Converting Image files to other format and sending it using socket programming in C++ RRS feed

  • Question

  • I am using Visual Studio 2013.

    The task is to send multiple images files to the server from client using socket programming in C++. How to exactly send multiple image files from client to server? Does this involve conversion of images to byte format? How exactly to proceed with this? Please help me with the problem!

    Thursday, September 7, 2017 9:25 AM

All replies

  • what protocol does the server support? ftp? http?


    Visual C++ MVP

    Friday, September 8, 2017 12:46 AM
  • Hi,

    Thank you for posting here.

    >>" Converting Image files to other format  "

    Which Image format need to convert. bmp png or other format?

    If the Image consists of RGB, first we need to get the original data by using open method.

    please reference the document about how to get rgb dara.

    Read RGB from bitmap - wrong values (of RGB); c++ code 

    now you have got the rgb data, you need to sent these data, I would suggest that you can use rtp protocol.

    The Real-time Transport Protocol (RTP) is a network protocol for delivering audio and video over IP networks

    Best Regards,

    Hart

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.


    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, September 8, 2017 7:15 AM
  • @Hart I want to send .jpg files. I don't know how to convert the image in binary and send to server and again retrieve the original image from binary. Please help
    Friday, September 8, 2017 2:21 PM
  • Hi Kuku5,

    Thank you for your feedback. 

    I think that you need to write a function with two parameters named GetRGBDate.

    First parse the head format that will tell you where it is really data.

    then you can copy the data using memcpy(pucDest, pucSrc, iLineWidthReal); 

    You can reference my code, but you need to modify, hope that it can help you.

    static int GetPixelDatasFrmBMP(unsigned char *aFileHead, PT_PixelDatas ptPixelDatas)
    {
    	BITMAPFILEHEADER *ptBITMAPFILEHEADER;
    	BITMAPINFOHEADER *ptBITMAPINFOHEADER;
    
    	int iWidth;
    	int iHeight;
    	int iBMPBpp;
    	int y;
    
    	unsigned char *pucSrc;
    	unsigned char *pucDest;
    	int iLineWidthAlign;
    	int iLineWidthReal;
    	
    
    	ptBITMAPFILEHEADER = (BITMAPFILEHEADER *)aFileHead;
    	ptBITMAPINFOHEADER = (BITMAPINFOHEADER *)(aFileHead + sizeof(BITMAPFILEHEADER));
    
    	iWidth = ptBITMAPINFOHEADER->biWidth;
    	iHeight = ptBITMAPINFOHEADER->biHeight;
    	iBMPBpp = ptBITMAPINFOHEADER->biBitCount;
    
    	if (iBMPBpp != 24)
    	{
    		DBG_PRINTF("iBMPBpp = %d\n", iBMPBpp);
    		DBG_PRINTF("sizeof(BITMAPFILEHEADER) = %d\n", sizeof(BITMAPFILEHEADER));
    		return -1;
    	}
    
    	ptPixelDatas->iWidth  = iWidth;
    	ptPixelDatas->iHeight = iHeight;
    	//ptPixelDatas->iBpp    = iBpp;
    	ptPixelDatas->aucPixelDatas = malloc(iWidth * iHeight * ptPixelDatas->iBpp / 8);
    	ptPixelDatas->iLineBytes    = iWidth * ptPixelDatas->iBpp / 8;
    	if (NULL == ptPixelDatas->aucPixelDatas)
    	{
    		return -1;
    	}
    
    	iLineWidthReal = iWidth * iBMPBpp / 8;
    	iLineWidthAlign = (iLineWidthReal + 3) & ~0x3;   
    		
    	pucSrc = aFileHead + ptBITMAPFILEHEADER->bfOffBits;
    	pucSrc = pucSrc + (iHeight - 1) * iLineWidthAlign;
    
    	pucDest = ptPixelDatas->aucPixelDatas;
    	
    	for (y = 0; y < iHeight; y++)
    	{		
    		//memcpy(pucDest, pucSrc, iLineWidthReal);
    		CovertOneLine(iWidth, iBMPBpp, ptPixelDatas->iBpp, pucSrc, pucDest);
    		pucSrc  -= iLineWidthAlign;
    		pucDest += ptPixelDatas->iLineBytes;
    	}
    	return 0;	
    }

    Best Regards,

    Hart


    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Baron Bi Wednesday, September 27, 2017 5:39 AM
    Monday, September 11, 2017 9:12 AM