Page 1 of 1

Print and save an Image

Posted: Sat Mar 27, 2021 5:44 pm
by Silvio.Falconi
I have an Image create wih FW_DrawImage()
How I can save and print this image ?

Re: Print and save an Image

Posted: Sun Mar 28, 2021 4:16 am
by nageswaragunupudi
FW_DrawImage() does not create an image. It only displays/prints an image on the screen or printer.

Re: Print and save an Image

Posted: Sun Mar 28, 2021 11:21 am
by Silvio.Falconi
thanks resolved

Re: Print and save an Image

Posted: Sun Mar 28, 2021 1:02 pm
by Otto
Silvio,
Would you mind posting how?
Best regards,
Otto

Re: Print and save an Image

Posted: Sun Mar 28, 2021 1:31 pm
by AntoninoP
Otto wrote:Silvio,
Would you mind posting how?
Best regards,
Otto

I helped Silvio, we used a modified version of TWindow:SaveToBmp( cBmpFile ), SaveToBitmap uses WndBitmap, I modified it to takes a region of window:

Code: Select all | Expand

//---------------------------------------------------------------------------//
// copied from fwh32\source\winapi\wndprint.c
HB_FUNC( WNDBITMAPRECT )  //  hWnd, aRect --> hBitmap
{
    HWND hWnd     = ( HWND ) fw_parH( 1 );
    HDC  hDC      = GetWindowDC( hWnd );
    HDC  hMem     = CreateCompatibleDC( hDC );
    RECT srcRect;
    RECT rct;
    HBITMAP hBmp, hOldBmp;
    srcRect.top    = hb_parvni( 2, 1 );
    srcRect.left   = hb_parvni( 2, 2 );
    srcRect.bottom = hb_parvni( 2, 3 );
    srcRect.right  = hb_parvni( 2, 4 );

    //GetWindowRect( hWnd, &rct );
    rct.left = 0;
    rct.top = 0;
    rct.right = srcRect.right - srcRect.left;
    rct.bottom = srcRect.bottom - srcRect.top;

    hBmp    = CreateCompatibleBitmap( hDC, rct.right, rct.bottom);
    hOldBmp = ( HBITMAP ) SelectObject( hMem, hBmp );

    BitBlt( hMem, 0, 0, rct.right, rct.bottom , hDC, srcRect.left, srcRect.top, SRCCOPY );

    SelectObject( hMem, hOldBmp );
    DeleteDC( hMem );
    ReleaseDC( hWnd, hDC );

    fw_retnll( hBmp );
}
//----------------------------------------------------------------------------//

Re: Print and save an Image

Posted: Sun Mar 28, 2021 1:40 pm
by Otto
Antonino, thank you for posting the solution.
Best regards,
Otto

Re: Print and save an Image

Posted: Sun Mar 28, 2021 2:14 pm
by nageswaragunupudi
Not necessary.
There is already a function

Code: Select all | Expand


MakeBkBmpEx( hWnd, top, left, width, height )
 

that does the same thing.

For the user, it is comfortable to use

Code: Select all | Expand


oWnd:SaveAsImage( anyimagefile, [ { top, left, bottom, right } ] )
 

Image file can be bmp, jpg, png, etc.
I don't see any need to modify the FWH sources.

Re: Print and save an Image

Posted: Sun Mar 28, 2021 6:01 pm
by AntoninoP
I am using 18.01, these function are "new"