Page 1 of 1

wndBitmap( oDlg:hWnd ) to variable?

PostPosted: Wed Dec 03, 2008 1:13 pm
by JC
I can make a bitmap with the dialod image with this:
Code: Select all  Expand view
hBmp := wndBitmap( oDlg:hWnd )


But, how I can write this image of hBmp into a simple variavel?

Save Image from Clipboard

PostPosted: Wed Dec 03, 2008 1:52 pm
by ukoenig
Hello JC,

You can use nCONVERT ( download from the Image-viewer-toppic )
You can use this tool also with command-lines from the DOS-prompt.
There is a script to save the Image of the clipboard to any Image-format.
I think Freeimage.dll doesn't support < save from clipboard >.
A easy way : Use xNVIEW and store the clipboard-image to any format
you like.

If You want to use nCONVERT, I can give You a sample, how to use it.
It is also possible to call it with WINEXEC like :

// Convert from clipboard to JPG and resize to 640x480
// -------------------------------------------------------------
cSCRIPT := "nconvert -out jpeg -resize 640 480 -clipboard"
WINEXEC("&cSCRIPT")

To use nCONVERT with WINEXEC, nCONVERT.exe must be in Your
working-directory.

I will test it and give You more detailed informations.

Regards
Uwe :lol:

PostPosted: Wed Dec 03, 2008 2:01 pm
by JC
Uwe,

Thanks but, I want another thing.

I want to save a handle hBmp to a variable of fivewin... something like this code:
Code: Select all  Expand view
cImage := someFunctionToSaveHbmp( hBmp )

And with this way to do, I will record this variable into a database or another place.

PostPosted: Wed Dec 03, 2008 2:05 pm
by JC
The function dibWrite( cBmpFile, hDib ) saves the dib handle into a file

Some like this to save into a variable?

Save Image from Clipboard

PostPosted: Wed Dec 03, 2008 2:21 pm
by ukoenig
Hello JC,

I think, something went wrong.
I answered to a question, how to save a image-capture from clipboard.
Your Question-text changed, or wrong toppic ?

Regards
Uwe :lol:

PostPosted: Wed Dec 03, 2008 2:27 pm
by JC
Uwe,

I think not!
wndBitmap( oDlg:hWnd ) to variable?

But, how I can write this image of hBmp into a simple variavel?

Into a simple variable of fivewin! Internally!

PostPosted: Wed Dec 03, 2008 10:47 pm
by Antonio Linares
JĂșlio,

Code: Select all  Expand view
   local cImage

   oDlg:SaveToBmp( "temp.txt" )

   cImage = MemoRead( "temp.txt" )

You can use "temp.txt" or "temp.bmp". It doesn't matter

PostPosted: Thu Dec 04, 2008 1:03 pm
by JC
Antonio,

I have used this solution but in truth, I did not want to have to write a file to disk.
Just like on resolving of method ::loadFromString (), I would like something like this.

PostPosted: Thu Dec 04, 2008 3:17 pm
by Antonio Linares
Please try this DibToStr():
Code: Select all  Expand view
#pragma BEGINDUMP

#include <windows.h>
#include <hbapi.h>

typedef FAR * FARP;

WORD far pascal wDIBColors( LPBITMAPINFOHEADER lpBmp );

char * DibToStr( HGLOBAL hDIB, unsigned long * pulSize )
{
   LPBITMAPINFO Info = ( LPBITMAPINFO ) GlobalLock( hDIB );
   void * Bits  = ( void * ) ( ( FARP ) Info + Info->bmiHeader.biSize +
                       wDIBColors( ( LPBITMAPINFOHEADER ) Info ) * sizeof( RGBQUAD ) );
   unsigned long ulSize = GlobalSize( ( HGLOBAL ) Info );
   BITMAPFILEHEADER bmf;
   int hBmp;
   char * pStr = ( char * ) hb_xgrab( sizeof( bmf ) + ulSize );

   bmf.bfType      = 'BM';
   bmf.bfSize      = sizeof( bmf ) + ulSize;
   bmf.bfReserved1 = 0;
   bmf.bfReserved2 = 0;
   bmf.bfOffBits   = sizeof( bmf ) + ( FARP ) Bits - ( FARP ) Info;

   memcpy( pStr, ( const char * ) &bmf, sizeof( bmf ) );
   memcpy( pStr + sizeof( bmf ),  ( const char * ) Info, ulSize );
   GlobalUnlock( hDIB );

   * pulSize = sizeof( bmf ) + ulSize;

   return pStr;
}

//---------------------------------------------------------------------------//

HB_FUNC( DIBTOSTR )  // ( hDib ) --> cString
{
    unsigned long ulSize = 0;
    char * pStr = DibToStr( ( HGLOBAL ) hb_parnl( 1 ), &ulSize );         

    hb_retclen( pStr, ulSize );
    hb_xfree( ( void * ) pStr );
}

//---------------------------------------------------------------------------//

#pragma ENDDUMP

PostPosted: Thu Dec 04, 2008 5:21 pm
by JC
Antonio,

Thank you very much!
I will try this solution and report the results!