-
June 11th, 2007, 10:30 AM
#1
writre bitmap file
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????
-
June 11th, 2007, 10:46 AM
#2
Re: writre bitmap file
Open Paint, paste the clipboard buffer and then save it in bmp, jpg or (don't remember what other formats paint can create)
-
June 11th, 2007, 10:55 AM
#3
Re: writre bitmap file
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
-
June 11th, 2007, 11:24 AM
#4
Re: writre bitmap file
Originally Posted by iwtbapd
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????
Look at this thread for sample.
Cheers
-
June 11th, 2007, 06:39 PM
#5
Re: writre bitmap file
Originally Posted by S_M_A
Open Paint, paste the clipboard buffer and then save it in bmp, jpg or (don't remember what other formats paint can create)
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 file
-
June 12th, 2007, 12:16 PM
#6
Re: writre bitmap file
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.
-
June 14th, 2007, 03:47 AM
#7
Re: writre bitmap file
oh,never mind.thank for ur helping !!
-
June 14th, 2007, 06:11 PM
#8
Re: writre bitmap file
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();
-
June 22nd, 2007, 08:32 PM
#9
Re: writre bitmap file
Originally Posted by tiger12506
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).
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.
Can u explain more clearly about your solution
-
June 23rd, 2007, 09:11 AM
#10
Re: writre bitmap file
Originally Posted by iwtbapd
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.
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.
Cheers
-
July 2nd, 2009, 10:29 AM
#11
Re: writre bitmap file
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
-
July 5th, 2009, 01:13 AM
#12
Re: writre bitmap file
Originally Posted by cobayashi
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
Did you try?
Code:
HBITMAP hMyBmp = (HBITMAP)LoadImage( NULL,
_T("photo.bmp"),
IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE|LR_CREATEDIBSECTION);
Cheers
-
July 5th, 2009, 10:42 AM
#13
Re: writre bitmap file
Originally Posted by golanshahar
Did you try?
Code:
HBITMAP hMyBmp = (HBITMAP)LoadImage( NULL,
_T("photo.bmp"),
IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE|LR_CREATEDIBSECTION);
Cheers
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/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|