Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Writing StretchBlt to a file

Posted on 2006-06-19
5
Medium Priority
?
431 Views
Last Modified: 2008-02-01
I am currently working on a program that will take a screen capture and save it to a file, now I got that to work out just fine, but I am now attempting to to simeltaneuously create a thumbnails of the captured image by calling StretchBlt() immediatley following the screen capture. This works, and works well, but unfortuntely I cannot figure out how to write the contents of the buffer (the thumbnailed image turns up in the corner of my monitor) to a file say 1_t.bmp. Does anyone know of a way to do this? I have been racking my brains on how to do this but have yet to get it to work.  Thanks.

0
Comment
Question by:atrc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 12

Accepted Solution

by:
rajeev_devin earned 1000 total points
ID: 16939383
0
 
LVL 22

Assisted Solution

by:mahesh1402
mahesh1402 earned 1000 total points
ID: 16958690
You may use CreateDIBSection for this purpose.. Refer following functions
Have a look at Draw, Resize() and Save() functions, m_hBitmap is your Handle to bitmap(HBITMAP) and m_dibsec is DIBSECTION object

void MyBitmap::Draw(HDC hDC, int x, int y, int width, int height) const
{
 BITMAP bmp;
 GetObject(m_hBitmap, sizeof(bmp), & bmp);
 HDC hMemDC = CreateCompatibleDC(NULL);
 HGDIOBJ hOld = SelectObject(hMemDC, m_hBitmap);
 StretchBlt(hDC, x, y, width, height, hMemDC, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
 SelectObject(hMemDC, hOld);
 DeleteDC(hMemDC);
}

void MyBitmap::Resize(const Bitmap & bmp, int newWidth, int newHeight)
{
 Release();
 m_dibsec = bmp.m_dibsec;
 m_dibsec.dsBmih.biWidth  = newWidth;
 m_dibsec.dsBmih.biHeight = newHeight;
 void * pBits = NULL;
 m_hBitmap = CreateDIBSection(NULL, (const BITMAPINFO *) & m_dibsec.dsBmih,
 DIB_RGB_COLORS, & pBits, NULL, NULL);
 HDC hMemDC = CreateCompatibleDC(NULL);
 HGDIOBJ hOld = SelectObject(hMemDC, m_hBitmap);
 bmp.Draw(hMemDC, 0, 0, newWidth, newHeight);
 SelectObject(hMemDC, hOld);
 DeleteDC(hMemDC);
 Set();
}

int MyBitmap::GetPixelSize(void) const
{
 return ( m_dibsec.dsBmih.biWidth * m_dibsec.dsBmih.biBitCount + 31 ) / 32 * 4 * m_dibsec.dsBmih.biHeight;
}

BOOL MyBitmap::Save(const TCHAR * szFileName)
{
 HANDLE handle = CreateFile(szFileName, GENERIC_WRITE, FILE_SHARE_READ,  NULL, CREATE_NEW | CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

 if ( handle == INVALID_HANDLE_VALUE )
  return FALSE;

 BITMAPFILEHEADER bmFH;

 int nHeadSize = sizeof(BITMAPINFOHEADER);

 bmFH.bfType      = 0x4D42;
 bmFH.bfSize      = nHeadSize + GetPixelSize();
 bmFH.bfReserved1 = 0;
 bmFH.bfReserved2 = 0;
 bmFH.bfOffBits   = nHeadSize + sizeof(BITMAPFILEHEADER);

 DWORD dwRead = 0;
 WriteFile(handle, & bmFH, sizeof(bmFH), & dwRead, NULL);

 WriteFile(handle, & m_dibsec.dsBmih,      nHeadSize,   & dwRead, NULL);
 WriteFile(handle, m_dibsec.dsBm.bmBits, GetPixelSize(), & dwRead, NULL);

 CloseHandle(handle);

 return TRUE;
}

-MAHESH
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16958714
In above Draw() function StretchBlt is used to stretch bitmap and in Resize() function CreateDIBSection() and Draw() used to construct object for stretched bitmap and then in Save() BMP file is created from stretched bitmap object ....which meets your requirement.

-MAHESH
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question