Página 1 de 1

Saving a Canvas as an image file

Publicado: Jue May 28, 2009 12:28 am
por Guest
Hi,
After Creating a number of line graphs on a canvas, is there a way to
save the entire canvas as a graphics file? It doesn't matter whether
it's a bitmap or tiff or whatever.

Saving a Canvas as an image file

Publicado: Jue May 28, 2009 12:03 pm
por ignacio
Childers,
You may use: XA_CaptureBitmap( <hWnd>, [<aRect>] ) --> hBitmap
In case you are drawing into a Window (Form). If you want to do the same job
using a printer canvas is a not a good idea since the bitmap will normally
have a tremendous size.
Regards,
--
Ignacio Ortiz de Zúñiga
Xailer support / Soporte de Xailer
http://www.xailer.com
http://www.xailer.info
"Childers" <NoSpamPlease@nycap.rr.com> escribió en el mensaje
news:4a1dbebe$[email=1@svctag-j7w3v3j....]1@svctag-j7w3v3j....[/email]
> Hi,
>
> After Creating a number of line graphs on a canvas, is there a way to save
> the entire canvas as a graphics file? It doesn't matter whether it's a
> bitmap or tiff or whatever.

Saving a Canvas as an image file

Publicado: Jue May 28, 2009 12:03 pm
por ignacio
Childers,
You may use: XA_CaptureBitmap( <hWnd>, [<aRect>] ) --> hBitmap
In case you are drawing into a Window (Form). If you want to do the same job
using a printer canvas is a not a good idea since the bitmap will normally
have a tremendous size.
Regards,
--
Ignacio Ortiz de Zúñiga
Xailer support / Soporte de Xailer
http://www.xailer.com
http://www.xailer.info
"Childers" <NoSpamPlease@nycap.rr.com> escribió en el mensaje
news:4a1dbebe$[email=1@svctag-j7w3v3j....]1@svctag-j7w3v3j....[/email]
> Hi,
>
> After Creating a number of line graphs on a canvas, is there a way to save
> the entire canvas as a graphics file? It doesn't matter whether it's a
> bitmap or tiff or whatever.

Saving a Canvas as an image file

Publicado: Vie May 29, 2009 12:20 am
por Guest
>>You may use: XA_CaptureBitmap( <hWnd>, [<aRect>] ) --> hBitmap
In case you are drawing into a Window (Form). If you want to do the same
job using a printer canvas is a not a good idea since the bitmap will
normally have a tremendous size.
Regards,<<
Ok, thanks. Using the above suggestion, the following works:
hBitMapImage := XA_CaptureBitMap( GetActiveWindow() )
oGraphBitMap := TBitMap():CreateFromHandle( hBitMapImage )
oGraphBitMap:Save( "C:DownloadTestBitMap.bmp" )
, but it captures the form, which includes the canvas. That's workable.
But is there a way to capture only the canvas, without any of the other
objects on the form? How do we obtain the window handle for only the
canvas?

Saving a Canvas as an image file

Publicado: Vie May 29, 2009 12:20 am
por Guest
>>You may use: XA_CaptureBitmap( <hWnd>, [<aRect>] ) --> hBitmap
In case you are drawing into a Window (Form). If you want to do the same
job using a printer canvas is a not a good idea since the bitmap will
normally have a tremendous size.
Regards,<<
Ok, thanks. Using the above suggestion, the following works:
hBitMapImage := XA_CaptureBitMap( GetActiveWindow() )
oGraphBitMap := TBitMap():CreateFromHandle( hBitMapImage )
oGraphBitMap:Save( "C:DownloadTestBitMap.bmp" )
, but it captures the form, which includes the canvas. That's workable.
But is there a way to capture only the canvas, without any of the other
objects on the form? How do we obtain the window handle for only the
canvas?

Saving a Canvas as an image file

Publicado: Vie May 29, 2009 9:42 am
por ignacio
Childers,
You may use aRect to only get the window client rectangle.
In order to capture the canvas, you need some C acknowledge. I include with
this message the code of XA_CaptureBitmap() that can serve you as a starting
point
Regards,
XA_FUNC( XA_CAPTUREBITMAP ) // XA_CaptureBitmap( <hWnd>, [<aRect>] ) -->
hBitmap
{
HWND hwnd = (HWND) hb_parnl( 1 );
RECT rect;
HDC hdc = GetDC( hwnd ), hdcBmp;
HBITMAP hBmp;
if ( hb_pcount() > 1 )
{
rect.left = hb_parnl( 2 );
rect.top = hb_parnl( 3 );
rect.bottom = hb_parnl( 4 );
rect.right = hb_parnl( 5 );
}
else
GetClientRect( hwnd, &rect );
hdcBmp = CreateCompatibleDC( hdc );
hBmp = CreateCompatibleBitmap( hdc, rect.right - rect.left, rect.bottom -
rect.top );
SelectObject( hdcBmp, hBmp );
BitBlt( hdcBmp, 0, 0, rect.right - rect.left, rect.bottom - rect.top,
hdc, rect.left, rect.top, SRCCOPY );
DeleteDC( hdcBmp );
ReleaseDC( hwnd, hdc );
hb_retnl( (long) hBmp );
}
--
Ignacio Ortiz de Zúñiga
Xailer support / Soporte de Xailer
http://www.xailer.com
http://www.xailer.info
"Childers" <NoSpamPlease@nycap.rr.com> escribió en el mensaje
news:4a1f0e3c$[email=2@svctag-j7w3v3j....]2@svctag-j7w3v3j....[/email]
> >>You may use: XA_CaptureBitmap( <hWnd>, [<aRect>] ) --> hBitmap
>
> In case you are drawing into a Window (Form). If you want to do the same
> job using a printer canvas is a not a good idea since the bitmap will
> normally have a tremendous size.
>
> Regards,<<
>
> Ok, thanks. Using the above suggestion, the following works:
>
>
> hBitMapImage := XA_CaptureBitMap( GetActiveWindow() )
> oGraphBitMap := TBitMap():CreateFromHandle( hBitMapImage )
> oGraphBitMap:Save( "C:DownloadTestBitMap.bmp" )
>
>
> , but it captures the form, which includes the canvas. That's workable.
>
> But is there a way to capture only the canvas, without any of the other
> objects on the form? How do we obtain the window handle for only the
> canvas?
>
>
>

Saving a Canvas as an image file

Publicado: Vie May 29, 2009 9:42 am
por ignacio
Childers,
You may use aRect to only get the window client rectangle.
In order to capture the canvas, you need some C acknowledge. I include with
this message the code of XA_CaptureBitmap() that can serve you as a starting
point
Regards,
XA_FUNC( XA_CAPTUREBITMAP ) // XA_CaptureBitmap( <hWnd>, [<aRect>] ) -->
hBitmap
{
HWND hwnd = (HWND) hb_parnl( 1 );
RECT rect;
HDC hdc = GetDC( hwnd ), hdcBmp;
HBITMAP hBmp;
if ( hb_pcount() > 1 )
{
rect.left = hb_parnl( 2 );
rect.top = hb_parnl( 3 );
rect.bottom = hb_parnl( 4 );
rect.right = hb_parnl( 5 );
}
else
GetClientRect( hwnd, &rect );
hdcBmp = CreateCompatibleDC( hdc );
hBmp = CreateCompatibleBitmap( hdc, rect.right - rect.left, rect.bottom -
rect.top );
SelectObject( hdcBmp, hBmp );
BitBlt( hdcBmp, 0, 0, rect.right - rect.left, rect.bottom - rect.top,
hdc, rect.left, rect.top, SRCCOPY );
DeleteDC( hdcBmp );
ReleaseDC( hwnd, hdc );
hb_retnl( (long) hBmp );
}
--
Ignacio Ortiz de Zúñiga
Xailer support / Soporte de Xailer
http://www.xailer.com
http://www.xailer.info
"Childers" <NoSpamPlease@nycap.rr.com> escribió en el mensaje
news:4a1f0e3c$[email=2@svctag-j7w3v3j....]2@svctag-j7w3v3j....[/email]
> >>You may use: XA_CaptureBitmap( <hWnd>, [<aRect>] ) --> hBitmap
>
> In case you are drawing into a Window (Form). If you want to do the same
> job using a printer canvas is a not a good idea since the bitmap will
> normally have a tremendous size.
>
> Regards,<<
>
> Ok, thanks. Using the above suggestion, the following works:
>
>
> hBitMapImage := XA_CaptureBitMap( GetActiveWindow() )
> oGraphBitMap := TBitMap():CreateFromHandle( hBitMapImage )
> oGraphBitMap:Save( "C:DownloadTestBitMap.bmp" )
>
>
> , but it captures the form, which includes the canvas. That's workable.
>
> But is there a way to capture only the canvas, without any of the other
> objects on the form? How do we obtain the window handle for only the
> canvas?
>
>
>