Print and save an Image

Post Reply
User avatar
Silvio.Falconi
Posts: 7170
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 5 times

Print and save an Image

Post by Silvio.Falconi »

I have an Image create wih FW_DrawImage()
How I can save and print this image ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
nageswaragunupudi
Posts: 10729
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 10 times
Contact:

Re: Print and save an Image

Post by nageswaragunupudi »

FW_DrawImage() does not create an image. It only displays/prints an image on the screen or printer.
Regards

G. N. Rao.
Hyderabad, India
User avatar
Silvio.Falconi
Posts: 7170
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 5 times

Re: Print and save an Image

Post by Silvio.Falconi »

thanks resolved
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Otto
Posts: 6414
Joined: Fri Oct 07, 2005 7:07 pm
Has thanked: 31 times
Been thanked: 2 times
Contact:

Re: Print and save an Image

Post by Otto »

Silvio,
Would you mind posting how?
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
AntoninoP
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy
Contact:

Re: Print and save an Image

Post 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 );
}
//----------------------------------------------------------------------------//
User avatar
Otto
Posts: 6414
Joined: Fri Oct 07, 2005 7:07 pm
Has thanked: 31 times
Been thanked: 2 times
Contact:

Re: Print and save an Image

Post by Otto »

Antonino, thank you for posting the solution.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
nageswaragunupudi
Posts: 10729
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 10 times
Contact:

Re: Print and save an Image

Post 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.
Regards

G. N. Rao.
Hyderabad, India
AntoninoP
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy
Contact:

Re: Print and save an Image

Post by AntoninoP »

I am using 18.01, these function are "new"
Post Reply