Page 1 of 2
How to save the Wndcopy()'s Clipboard's output to a BMP ?
Posted: Thu Oct 11, 2007 1:24 pm
by RAMESHBABU
Hello friends,
As per the subject.
- Ramesh Babu
Re: How to save the Wndcopy()'s Clipboard's output to a BMP
Posted: Thu Oct 11, 2007 2:09 pm
by wmormar
RAMESHBABU wrote:Hello friends,
As per the subject.
- Ramesh Babu
Ramesh,
oWnd:SaveToBmp( "mibmp.bmp" )
Posted: Thu Oct 11, 2007 4:35 pm
by RAMESHBABU
Hello Mr. Wmormar
This is not that much simple. At least in FWH 2.8 xHarbour (0.99.71 Simplex) !.
Which version of FWH and xHarbour you are using and you got it working?
I have used several methods to achive this well with in FWH. But I did
not suceeed. I had to adopt a long work around to achive this.
Thanks for your response.
- Ramesh Babu P
Posted: Thu Oct 11, 2007 5:01 pm
by Antonio Linares
Ramesh,
Code: Select all
METHOD SaveToBmp( cBmpFile ) CLASS TWindow
local hBmp := WndBitmap( ::hWnd )
local hDib := DibFromBitmap( hBmp )
DibWrite( cBmpFile, hDib )
GloBalFree( hDib )
DeleteObject( hBmp )
return ( File( cBmpFile ) )
Posted: Thu Oct 11, 2007 8:11 pm
by James Bott
Antonio,
Is that saving a bitmap snapshot of the window to a BMP file?
I think Ramesh wants to save a bitmap that is in the clipboard to a file. Is that right Ramesh?
James
Posted: Fri Oct 12, 2007 1:19 am
by RAMESHBABU
Mr.Antonio
Thanks for your attention.
The following code is a "savedbmp.bmp" with only 14 bytes !.
Code: Select all
#include "Fivewin.ch"
FUNCTION Main()
LOCAL oWnd
DEFINE WINDOW oWnd TITLE "SaveToBmp"
@ 9, 2 BUTTON "Save To Bmp" ;
SIZE 210, 30 ;
ACTION ( oWnd:SaveToBmp("SavedBmp.Bmp"), MsgInfo("Saved") )
ACTIVATE WINDOW oWnd
RETURN nil
As Mr.James said, I need to save the contents of clipboard to a BMP file.
I am using FWH 2.8 (Sep. build) + xHarbour 0.99.71 (Simplex)
This was working very well in our earlier versioins. But it is not working.
And I have come across several postings on our forum with the same
complaint that they are getting a saved BMP file only with 14 bytes.
Currently I have adopted a very long work around using some 3 party utilitys to achive this result.
Plase do help.
- Ramesh Babu P
Posted: Fri Oct 12, 2007 6:13 am
by Antonio Linares
Ramesh,
Your code is working fine here using FWH 7.10 and Vista Ultimate 32 bits:
Using Harbour:
10/12/2007 08:12 1,168 b32.bc
10/12/2007 08:11 0 clip.log
10/12/2007 08:12 630,074 SavedBmp.Bmp
10/12/2007 08:11 4,694 test.c
10/12/2007 08:12 1,086,976 test.exe
10/12/2007 08:12 373,443 test.map
10/12/2007 08:12 2,096 test.obj
10/12/2007 08:11 1,147 test.ppo
10/12/2007 08:11 293 test.prg
10/12/2007 08:12 458,752 test.tds
10 File(s) 2,558,643 bytes
Using xHarbour:
10/12/2007 08:16 <DIR> .
10/12/2007 08:16 <DIR> ..
10/12/2007 08:16 964 b32.bc
10/12/2007 08:16 480 clip.log
10/12/2007 08:16 630,074 SavedBmp.Bmp
10/12/2007 08:16 1,278,464 test.exe
10/12/2007 08:16 435,917 test.map
10/12/2007 08:16 10,604 test.obj
10/12/2007 08:16 1,253 test.ppo
10/12/2007 08:11 293 test.prg
10/12/2007 08:16 655,360 test.tds
9 File(s) 3,013,409 bytes
Posted: Fri Oct 12, 2007 8:27 am
by RAMESHBABU
Mr.Antonio
As I have already pointed, the same functionality was working OK prior to
FWH 2.8 and it stopped working in 2.8 I don't know why.
Can you please check with FWH 2.8 (Sep. build) + xHarbour 0.99.71 (Simplex) and suggest me any way out ?
For your information, we have spoken several times in the forum earlier on
the same issue. And you said the same thing. I hope atleast this time so
will suggest me a way out. Because the working around way I am following presently is not giving the expected result some times and I am
facing problems.
My previous posting on the same subject for your reference:
http://fivetechsoft.com/forums/viewtop ... =save2bmp
Thanks
- Ramesh Babu P
Posted: Fri Oct 12, 2007 9:31 am
by Antonio Linares
Ramesh,
> Can you please check with FWH 2.8 (Sep. build)
We can't provide tech support for 2.8 september year 2006. There have been lots of changes both in Harbour/xHarbour and FWH. Please understand it.
We can only suggest you to upgrade to FWH 7.10
Posted: Fri Oct 12, 2007 4:25 pm
by James Bott
Ramesh,
Try this:
Code: Select all
oClipBoard := TClipBoard():New( CF_BITMAP )
oClipBoard:Open()
hBmp := oClipBoard:GetData() // Get handle bitmap
oClipBoard:Close()
hDib := DibFromBitmap( hBmp ) // Write from handle
If Empty( hDib )
MsgInfo("Can't make a bitmap","Error")
RETURN
EndIf
DibWrite( "BmpFile.bmp", hDib )
GlobalFree( hDib )
DeleteObject( hBmp )
Posted: Sat Oct 13, 2007 9:56 am
by RAMESHBABU
Mr.James
Thank you very much for your support.
Actually the DibWrite(...) function it self not functioning properly.
It is generating a BMP file with only 14 bytes !. I have tried several
ways including yours.
Still the same problem.
Thank you once again.
- Ramesh Babu P
Posted: Sat Oct 13, 2007 11:07 am
by Antonio Linares
Ramesh,
Please copy here the source code of your FWH DibWrite(), thanks
Posted: Sat Oct 13, 2007 11:35 am
by RAMESHBABU
Mr.Antonio
Thank you very much for not leaving me in vain.
Code: Select all
BOOL DibWrite( LPSTR szFileName, HGLOBAL hDIB )
{
LPBITMAPINFO Info = ( LPBITMAPINFO ) GlobalLock( hDIB );
void huge * Bits = ( void huge * ) ( ( FARP ) Info + Info->bmiHeader.biSize +
wDIBColors( ( LPBITMAPINFOHEADER ) Info ) * sizeof( RGBQUAD ) );
long lSize = GlobalSize( ( HGLOBAL ) Info );
BITMAPFILEHEADER bmf;
int hBmp;
bmf.bfType = 'BM';
bmf.bfSize = sizeof( bmf ) + lSize;
bmf.bfReserved1 = 0;
bmf.bfReserved2 = 0;
bmf.bfOffBits = sizeof( bmf ) + ( FARP ) Bits - ( FARP ) Info;
#ifndef UNICODE
if( ( hBmp = _lcreat( szFileName, 0 ) ) != HFILE_ERROR )
{
_hwrite( hBmp, ( const char * ) &bmf, sizeof( bmf ) );
_hwrite( hBmp, ( const char * ) Info, lSize );
_lclose( hBmp );
GlobalUnlock( hDIB );
return TRUE;
}
#else
if( ( hBmp = hb_fsCreate( ( unsigned char * ) szFileName, 0 ) ) != ( int ) INVALID_HANDLE_VALUE )
{
hb_fsWriteLarge( hBmp, ( unsigned char * ) &bmf, sizeof( bmf ) );
hb_fsWriteLarge( hBmp, ( unsigned char * ) Info, lSize );
hb_fsClose( hBmp );
GlobalUnlock( hDIB );
return TRUE;
}
#endif
else
{
GlobalUnlock( hDIB );
return FALSE;
}
}
//---------------------------------------------------------------------------//
CLIPPER DIBWRITE( PARAMS ) // ( cFileName, hDib ) --> lSuccess
{
_retl( DibWrite( _parc( 1 ), ( HGLOBAL ) _parnl( 2 ) ) );
}
Please look into it and suggest me, if any thing is to be modified.
Thank you once again,
- Ramesh Babu P
FWH 2.8 (Sep Build) + xHarbour 0.99.71 (Simplex)
Posted: Sat Oct 13, 2007 11:40 am
by Enrico Maria Giordano
It seems identical to the one in the current FWH release.
EMG
Posted: Sat Oct 13, 2007 11:42 am
by Antonio Linares
Ramesh,
Please email it to me, the entire dib.c, thanks