Click here to Skip to main content
11,789,706 members (60,543 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VC8.0
I have just used lpBits to store the binary data. But in database i see only 24bytes. How to convert the find the binary data of the image. To store it in the database.

HDC hScrDC = ::GetDC(NULL);
	BYTE *lpBitmapBits = NULL; 
	int nWidth = GetSystemMetrics(SM_CXSCREEN);
	int nHeight = GetSystemMetrics(SM_CYSCREEN); 
	hMemDC = ::CreateCompatibleDC(hScrDC); 
	ZeroMemory(&bi, sizeof(BITMAPINFO));
	bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	bi.bmiHeader.biWidth = nWidth;
	bi.bmiHeader.biHeight = nHeight;
	bi.bmiHeader.biPlanes = 1;
	bi.bmiHeader.biBitCount = 24;
	HBITMAP bitmap = ::CreateDIBSection(hMemDC, &bi, DIB_RGB_COLORS, (LPVOID*)&lpBitmapBits, NULL, 0);
	HGDIOBJ oldbmp = ::SelectObject(hMemDC, bitmap); 
	::BitBlt(hMemDC, 0, 0, nWidth, nHeight, hScrDC, 0, 0, SRCCOPY);
	ZeroMemory(&bh, sizeof(BITMAPFILEHEADER));
	bh.bfType = 0x4d42; //bitmap 
	bh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
	bh.bfSize = bh.bfOffBits + ((nWidth*nHeight)*3);
         lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, bi.bmiHeader.biSizeImage);	
	CFile file;	
	char buffer[1000];
	DWORD threadId;
  int value = 10;
  //hThread = CreateThread( NULL, 0, runThread, &value, 0, &threadId);
	for(int c=0;c<10;c++)
		 CString sName(buffer);  
         LPCTSTR lpszName = sName;  
		if(file.Open(lpszName, CFile::modeCreate | CFile::modeWrite))
			file.Write(&bh, sizeof(BITMAPFILEHEADER));
			file.Write(&(bi.bmiHeader), sizeof(BITMAPINFOHEADER));
			file.Write(lpBitmapBits, 3 * nWidth * nHeight);
	::SelectObject(hMemDC, oldbmp);
	::ReleaseDC(NULL, hScrDC);
Posted 29-Apr-11 19:48pm
Edited 2-May-11 23:57pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

What's your question?
The string D:\image%u.jpg should be D:\\image%u.jpg
Gokulnath007 at 30-Apr-11 5:49am
I have the following code to take the screenshots and storing it in the hard disk. I want to convert it to BLOB data. In this code, where is the blob data found and how to convert the image into the blob data??
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

For the first: bitmap (BMP) format is not automatically converted to jpeg (JPG).
BLOB stands for Binary Large OBject, and is used to store binary data into a database. This can be everything. So you can store the whole bitmap in a database.
You should open a stream to your BLOB in database and write to it like into a file.
Gokulnath007 at 2-May-11 0:25am
Could you add more points regarding "converting the image into blob data"
mbue at 3-May-11 7:37am
In your code i cant see accessing a database. How do you access the database?
Gokulnath007 at 4-May-11 6:54am
I have added below this code once the values from the image to blob is over. Need to save it in the database.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 999
1 Maciej Los 765
2 KrunalRohit 686
3 CPallini 606
4 Richard MacCutchan 430

Advertise | Privacy | Mobile
Web02 | 2.8.1509028.1 | Last Updated 3 May 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100