I have captured the screen and copy the image to clipboard.
Now, i want to write the image from clipboard to bitmap file.
but i don't know how to write a bit map file, any suggestion for me,.please????
Printable View
I have captured the screen and copy the image to clipboard.
Now, i want to write the image from clipboard to bitmap file.
but i don't know how to write a bit map file, any suggestion for me,.please????
Open Paint, paste the clipboard buffer and then save it in bmp, jpg or (don't remember what other formats paint can create)
using vc++
then go through this link
http://msdn2.microsoft.com/en-us/lib...ax(VS.80).aspx
read it , may be it will help you
else best way S_M_A already told you
Look at this thread for sample.Quote:
Originally Posted by iwtbapd
Cheers
Oh it's so easy . But i don't want to do it,i want to create a bitmap file,write the image to the fileQuote:
Originally Posted by S_M_A
I'm sorry iwtbapd, I realized that later on but then the post was already there. Of course I could have deleted it but then it would have been loose references.
I've been thinking about it though. I wonder if Paint actually can be used as a "save-to-file server"? Would be an easy way not to have to bother about different file formats, just open Paint, send a WM_PASTE and then make Paint save to file.
Hope the answers from golanshahar & ashukasama helped you.
oh,never mind.thank for ur helping !!
I doubt if Paint could be used that way SMA. But after reading this thread, I've determined that it's incredibly easy to write your own "save-to-file server", the key being that almost all (if not all) applications cut and/or copy pictures to the clipboard as bitmaps! So the save-to-file server doesn't have to know about any other formats. Here is what is needed (well, and the Writebmp func).
Code:OpenClipboard(hwnd);
HBITMAP hbmp = GetClipboardData(CF_BITMAP);
CloseClipboard();
oh, my problem is unable to write bitmap file. When you had a HBITMAP,how could you write this bitmap to file.And i can't u <fstream.h> for using ofstream.Quote:
Originally Posted by tiger12506
Can u explain more clearly about your solution
You can use ::GetBitmapBits() to get the raw bits from the image, and ::GetObject() to get the width/height/bpp and you have all the info in order to write it to file.Quote:
Originally Posted by iwtbapd
Cheers
First of all hello people in this great forum. Good post this one.
I tried using "golanshahar" and "dave2k" tips but I got a nasty incompatibility with bmps.
In (1) and (2) I capture and save a desktop photo. The photo seems ok, 32 bits depth, good width, high and image, opens ok in windows, paint, photoshop.. BUT when I try to load again using LoadImage function, I got a NULL HANDLE returned with 0 error, when loadImage works okey for any other bmp not generated this way.
Very confused.. any help appreciated..
// (1) MAKE DESKTOP PHOTO
RECT rc;
HWND hWnd = ::GetDesktopWindow();
::GetWindowRect(hWnd, &rc);
int w = rc.right-rc.left;
int h = rc.bottom-rc.top;
HDC hDC = ::GetDC(0);
HDC memDC = ::CreateCompatibleDC(hDC);
HBITMAP memBM = ::CreateCompatibleBitmap(hDC, w, h);
::SelectObject(memDC, memBM );
::BitBlt(memDC, 0, 0, w, h , hDC, rc.left, rc.top , SRCCOPY );
int size = 4 * w * h;
BYTE *lpBits = new BYTE[size];
::GetBitmapBits((HBITMAP)memBM,size,(int*)lpBits);
// here you have the data both in memBM and also in rawBits
::ReleaseDC( 0, hDC );
// (2) WRITE TO PHYSICAL FILE BMP
WriteBmp("photo.bmp", w, h, 32,(int*)lpBits);
delete [] lpBits;
// (3) TRY TO LOAD THE PHYSICAL FILE BMP GENERATED
HBITMAP hMyBmp = (HBITMAP)LoadImage( NULL,
_T("photo.bmp"),
IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE);
if ( hMyBmp == NULL )
{
//GetLastError();
CWnd *Display;
Display = GetDlgItem(IDC_EDIT1);
CString strError;
strError.Format(_T("ERROR: %i, NULL HANDLE RETURNED"), GetLastError() );
LPTSTR lpszError;
lpszError = strError.GetBuffer(strError.GetLength());
Display->SetWindowTextW(lpszError);
}
Also tried another "writebmp" alike function found in this page http://sarathc.wordpress.com/2007/03...itmap-to-file/ in case there was a problem in writebmp but still the same problem
Thank you Golanshahar :)
Doesn't work either. I think there is a some small bug or lack of info written in WriteBmp. Bmps generated are good enough to to be seen in apps, including the windows viewer.. but not good enough to be loaded with LoadImage as "Windows NT-based systems, performs stricter validation of LoadImage()" :
http://support.microsoft.com/kb/329092/en-us/