Click here to Skip to main content
Rate this: bad
good
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);
	HDC hMemDC = NULL;
 
	BYTE *lpBitmapBits = NULL; 
 
	int nWidth = GetSystemMetrics(SM_CXSCREEN);
	int nHeight = GetSystemMetrics(SM_CYSCREEN); 
 
	hMemDC = ::CreateCompatibleDC(hScrDC); 
 
	BITMAPINFO bi; 
	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);
 
	BITMAPFILEHEADER bh;
	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++)
	{
		 sprintf_s(buffer,"D:\image%u.jpg",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);
			file.Close();
			Sleep(10000);
		}
		
	}
	::SelectObject(hMemDC, oldbmp);
	::DeleteObject(bitmap);
	::DeleteObject(hMemDC);
	::ReleaseDC(NULL, hScrDC);
Posted 29-Apr-11 20:48pm
Edited 3-May-11 0:57am
v2
Rate this: bad
good
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
  Permalink  
Comments
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
good
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.
Regards.
  Permalink  
Comments
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?
Regards.
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 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,382


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 3 May 2011
Copyright © CodeProject, 1999-2014
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