How to save the Wndcopy()'s Clipboard's output to a BMP ?

How to save the Wndcopy()'s Clipboard's output to a BMP ?

Postby RAMESHBABU » Thu Oct 11, 2007 1:24 pm

Hello friends,

As per the subject.

- Ramesh Babu
User avatar
RAMESHBABU
 
Posts: 625
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: How to save the Wndcopy()'s Clipboard's output to a BMP

Postby wmormar » Thu Oct 11, 2007 2:09 pm

RAMESHBABU wrote:Hello friends,

As per the subject.

- Ramesh Babu


Ramesh,

oWnd:SaveToBmp( "mibmp.bmp" )
William, Morales
Saludos

méxico.sureste
User avatar
wmormar
 
Posts: 1074
Joined: Fri Oct 07, 2005 10:41 pm
Location: México

Postby RAMESHBABU » Thu Oct 11, 2007 4:35 pm

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
User avatar
RAMESHBABU
 
Posts: 625
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Postby Antonio Linares » Thu Oct 11, 2007 5:01 pm

Ramesh,

Code: Select all  Expand view  RUN
METHOD SaveToBmp( cBmpFile ) CLASS TWindow

   local hBmp := WndBitmap( ::hWnd )
   local hDib := DibFromBitmap( hBmp )

   DibWrite( cBmpFile, hDib )
   GloBalFree( hDib )
   DeleteObject( hBmp )

return ( File( cBmpFile ) )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby James Bott » Thu Oct 11, 2007 8:11 pm

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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby RAMESHBABU » Fri Oct 12, 2007 1:19 am

Mr.Antonio

Thanks for your attention.

The following code is a "savedbmp.bmp" with only 14 bytes !.

Code: Select all  Expand view  RUN
#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
User avatar
RAMESHBABU
 
Posts: 625
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Postby Antonio Linares » Fri Oct 12, 2007 6:13 am

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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby RAMESHBABU » Fri Oct 12, 2007 8:27 am

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:

[url]
http://fivetechsoft.com/forums/viewtopi ... t=save2bmp
[/url]

Thanks

- Ramesh Babu P
User avatar
RAMESHBABU
 
Posts: 625
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Postby Antonio Linares » Fri Oct 12, 2007 9:31 am

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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby James Bott » Fri Oct 12, 2007 4:25 pm

Ramesh,

Try this:

Code: Select all  Expand view  RUN
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 )
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby RAMESHBABU » Sat Oct 13, 2007 9:56 am

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
User avatar
RAMESHBABU
 
Posts: 625
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Postby Antonio Linares » Sat Oct 13, 2007 11:07 am

Ramesh,

Please copy here the source code of your FWH DibWrite(), thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby RAMESHBABU » Sat Oct 13, 2007 11:35 am

Mr.Antonio

Thank you very much for not leaving me in vain.

Code: Select all  Expand view  RUN
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)
User avatar
RAMESHBABU
 
Posts: 625
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Postby Enrico Maria Giordano » Sat Oct 13, 2007 11:40 am

It seems identical to the one in the current FWH release.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Antonio Linares » Sat Oct 13, 2007 11:42 am

Ramesh,

Please email it to me, the entire dib.c, thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 42 guests