BUG in SaveToBmp() / Antonio

BUG in SaveToBmp() / Antonio

Postby byte-one » Wed Oct 27, 2010 1:32 pm

If i save the window with oWin:SaveToBmp(cFile), the saved bitmap are splitted, when i display it with a graphic-viewer! This is only, the size from the window are greater!?
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: BUG in SaveToBmp() / Antonio

Postby Daniel Garcia-Gil » Wed Oct 27, 2010 3:09 pm

Gunther

i did support about this point in spanish forum, already include to next fivewin build
http://forums.fivetechsupport.com/viewtopic.php?p=105955#p105955

is necesary modify .C file compile and replace into fiveHC.lib
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: BUG in SaveToBmp() / Antonio

Postby byte-one » Wed Oct 27, 2010 8:21 pm

Daniel, can you post me the required changes in the .c-files? I catch also with a problem to save the bitmap as jpg. But only on XP the app is blocked in some cases.
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: BUG in SaveToBmp() / Antonio

Postby Daniel Garcia-Gil » Wed Oct 27, 2010 9:30 pm

Günther

change for .C Files
Tip: for build fivehc.lib you need harbour, no matter if you use xharbour


dib.c

add

Code: Select all  Expand view
char * DibToStr( HGLOBAL hDib, long * plSize )
{
   LPBITMAPINFO Info = ( LPBITMAPINFO ) GlobalLock( hDib );
   void * Bits  = ( void * ) ( ( char * ) Info + Info->bmiHeader.biSize +
                    wDIBColors( ( LPBITMAPINFOHEADER ) Info ) * sizeof( RGBQUAD ) );  
   BITMAPFILEHEADER bmf;
   char * pDib;
   long lSize;

   lSize = GlobalSize( ( HGLOBAL ) Info );
   
   pDib = hb_xgrab( sizeof( bmf ) + lSize );

   bmf.bfType      = 0x4D42;
   bmf.bfSize      = sizeof( bmf ) + lSize;
   bmf.bfReserved1 = 0;
   bmf.bfReserved2 = 0;
   bmf.bfOffBits   = sizeof( bmf ) + ( LONG ) Bits - ( LONG ) Info;  
   
   memcpy( pDib, &bmf, sizeof( bmf ) );
   memcpy( ( char * ) pDib + sizeof( bmf ), ( void * ) Info, lSize );
   lSize += sizeof( BITMAPFILEHEADER );
   *plSize = lSize;
   
   return pDib;
}


change

Code: Select all  Expand view

BOOL DibWrite( LPSTR szFileName, HGLOBAL hDIB )
{

   long lSize;
   char * pDib;
   int hBmp;
   
   pDib = DibToStr( hDIB, &lSize );

   #ifndef UNICODE
   if( ( hBmp = _lcreat( szFileName, 0 ) ) != HFILE_ERROR )
   {
      _hwrite( hBmp, ( const char * ) pDib, 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 * ) pDib, lSize );
      hb_fsClose( hBmp );
      GlobalUnlock( hDIB );
      return TRUE;
   }
   #endif
   else
   {
      GlobalUnlock( hDIB );
      return FALSE;
   }
}
 



dibbmp.c

add prototype

Code: Select all  Expand view
char * DibToStr( HGLOBAL hDib, long * plSize );


change
Code: Select all  Expand view

HB_FUNC( BMPTOSTR ) // hBmp --> cBitmapAsString
{
   HGLOBAL hDib = ( HGLOBAL ) DibFromBitmap( ( HBITMAP ) hb_parnl( 1 ), 0, 0, NULL );
   long lSize;
   char * pDib = DibToStr( hDib, &lSize );

   hb_retclen( pDib, lSize );
   
   GlobalUnlock( hDib );
   GlobalFree( hDib );
   hb_xfree( pDib );
}
 



other way you can add this code to main prg
Code: Select all  Expand view
#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>

WORD far pascal wDIBColors( LPBITMAPINFOHEADER );

HANDLE DibFromBitmap( HBITMAP, DWORD, WORD, HPALETTE );


char * DibToStr( HGLOBAL hDib, long * plSize )
{
   LPBITMAPINFO Info = ( LPBITMAPINFO ) GlobalLock( hDib );
   void * Bits  = ( void * ) ( ( char * ) Info + Info->bmiHeader.biSize +
                    wDIBColors( ( LPBITMAPINFOHEADER ) Info ) * sizeof( RGBQUAD ) );  
   BITMAPFILEHEADER bmf;
   char * pDib;
   long lSize;

   lSize = GlobalSize( ( HGLOBAL ) Info );
   
   pDib = hb_xgrab( sizeof( bmf ) + lSize );

   bmf.bfType      = 0x4D42;
   bmf.bfSize      = sizeof( bmf ) + lSize;
   bmf.bfReserved1 = 0;
   bmf.bfReserved2 = 0;
   bmf.bfOffBits   = sizeof( bmf ) + ( LONG ) Bits - ( LONG ) Info;  
   
   memcpy( pDib, &bmf, sizeof( bmf ) );
   memcpy( ( char * ) pDib + sizeof( bmf ), ( void * ) Info, lSize );
   lSize += sizeof( BITMAPFILEHEADER );
   *plSize = lSize;
   
   return pDib;
}


BOOL DibWrite( LPSTR szFileName, HGLOBAL hDIB )
{

   long lSize;
   char * pDib;
   int hBmp;
   
   pDib = DibToStr( hDIB, &lSize );

   #ifndef UNICODE
   if( ( hBmp = _lcreat( szFileName, 0 ) ) != HFILE_ERROR )
   {
      _hwrite( hBmp, ( const char * ) pDib, 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 * ) pDib, lSize );
      hb_fsClose( hBmp );
      GlobalUnlock( hDIB );
      return TRUE;
   }
   #endif
   else
   {
      GlobalUnlock( hDIB );
      return FALSE;
   }
}
 

HB_FUNC( BMPTOSTR ) // hBmp --> cBitmapAsString
{
   HGLOBAL hDib = ( HGLOBAL ) DibFromBitmap( ( HBITMAP ) hb_parnl( 1 ), 0, 0, NULL );
   long lSize;
   char * pDib = DibToStr( hDib, &lSize );

   hb_retclen( pDib, lSize );
   
   GlobalUnlock( hDib );
   GlobalFree( hDib );
   hb_xfree( pDib );
}


HB_FUNC( DIBWRITE )  // ( cFileName, hDib ) --> lSuccess
{
   hb_retl( DibWrite( ( char * ) hb_parc( 1 ), ( HGLOBAL ) hb_parnl( 2 ) ) );
}
 
#pragma ENDDUM
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: BUG in SaveToBmp() / Antonio

Postby byte-one » Thu Oct 28, 2010 11:37 am

Thanks Daniel! All is wonderfull. Also the error in XP is gone.
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 89 guests