Board index » cppbuilder » Objects Used for Graphing with BDS2006

Objects Used for Graphing with BDS2006


2007-08-13 04:51:49 AM
cppbuilder2
I need to draw mathematical plots. I am completely new to using
graphics under Windows, though I did a lot of it under DOS. So I have
some very basic questions.
Is there a "best choice" of object to draw on? TBitmap? TImage?
Something else? How is the object erased?
I'd like to zoom the image using a slider. Is there a direct way to
zoom?
 
 

Re:Objects Used for Graphing with BDS2006

Bob Penoyer < XXXX@XXXXX.COM >wrote:
Quote

I need to draw mathematical plots.
TChart is worth looking at.
Quote
I am completely new to using graphics under Windows, though
I did a lot of it under DOS.
Two different animals.
Quote
[...] Is there a "best choice" of object to draw on?
TBitmap? TImage? Something else?
Using the VCL, one draws on a TCanvas which TBitmap and TImage
and many other objects have. Using win32 API's, one draws on
and HDC which is the TCanvas::Handle.
Quote
How is the object erased?
That depends and your logic depends even if you care when it's
erased v/s drawn.
Quote
I'd like to zoom the image using a slider.
Simple (see below).
Quote
Is there a direct way to zoom?
The best way to zoom is to use two TBitmaps. The first TBitmap
contains the original image. The second TBitmap is used as the
displayed image. For the following, assume that BmpOriginal
is the original TBitmap and that BmpDisplay is the displayable
TBitmap:
void __fastcall TForm1::Zoom( [parameters] )
{
// set BmpDisplay's width
// set BpmDisplay's height
TRect R = Rect( 0, 0, BmpDisplay->Width, BmpDisplay->Height );
BmpDisplay->Canvas->StretchDraw( R, BmpOriginal->Canvas );
// At this point, the BmpDisplay is ready to be painted
// to the screen but you need a mechanism to cause it to
// be painted. Invalidate() does this but you need an
// object to Invalidate that handles painting the
// BmpDisplay.
PaintBox1->Invalidate()(;
}
Drop a TPaintBox on the form and use that for displaying the
desired TBitmap. When you Invalidate() the TPaintBox, it will be repainted so all you have to do now is add an OnPaint event to the TPaintBox and then use that event will to paint the
BmpDisplay image. For example:
//-------------------------------------------------------------
void __fastcall TForm2::PaintBox1Paint(TObject *Sender)
{
TRect R = Rect( 0, 0, BpmDisplay->Width, BpmDisplay->Height );
PaintBox1->Canvas->CopyRect( R, BpmDisplay->Canvas, R );
}
//-------------------------------------------------------------
~ JD
 

Re:Objects Used for Graphing with BDS2006

On 12 Aug 2007 20:15:46 -0700, "JD" < XXXX@XXXXX.COM >wrote:
Quote

Bob Penoyer < XXXX@XXXXX.COM >wrote:
>
>I need to draw mathematical plots.

TChart is worth looking at.

>I am completely new to using graphics under Windows, though
>I did a lot of it under DOS.

Two different animals.

>[...] Is there a "best choice" of object to draw on?
>TBitmap? TImage? Something else?

Using the VCL, one draws on a TCanvas which TBitmap and TImage
and many other objects have. Using win32 API's, one draws on
and HDC which is the TCanvas::Handle.

>How is the object erased?

That depends and your logic depends even if you care when it's
erased v/s drawn.

>I'd like to zoom the image using a slider.

Simple (see below).

>Is there a direct way to zoom?

The best way to zoom is to use two TBitmaps. The first TBitmap
contains the original image. The second TBitmap is used as the
displayed image. For the following, assume that BmpOriginal
is the original TBitmap and that BmpDisplay is the displayable
TBitmap:

void __fastcall TForm1::Zoom( [parameters] )
{
// set BmpDisplay's width
// set BpmDisplay's height
TRect R = Rect( 0, 0, BmpDisplay->Width, BmpDisplay->Height );
BmpDisplay->Canvas->StretchDraw( R, BmpOriginal->Canvas );
// At this point, the BmpDisplay is ready to be painted
// to the screen but you need a mechanism to cause it to
// be painted. Invalidate() does this but you need an
// object to Invalidate that handles painting the
// BmpDisplay.

PaintBox1->Invalidate()(;
}

Drop a TPaintBox on the form and use that for displaying the
desired TBitmap. When you Invalidate() the TPaintBox, it will be repainted so all you have to do now is add an OnPaint event to the TPaintBox and then use that event will to paint the
BmpDisplay image. For example:

//-------------------------------------------------------------
void __fastcall TForm2::PaintBox1Paint(TObject *Sender)
{
TRect R = Rect( 0, 0, BpmDisplay->Width, BpmDisplay->Height );
PaintBox1->Canvas->CopyRect( R, BpmDisplay->Canvas, R );
}
//-------------------------------------------------------------

~ JD
Thanks, JD.
 

{smallsort}

Re:Objects Used for Graphing with BDS2006

Bob Penoyer < XXXX@XXXXX.COM >wrote:
Quote

Thanks, JD.
Please direct your browser to:
info.borland.com/newsgroups/guide.html
and resd the guide lines. Note that you are warned that
over-quoting is reaseon to have your messages canceled
(deleted) from the server. For more, see here:
tinyurl.com/2o8nef
~ JD
 

Re:Objects Used for Graphing with BDS2006

Hi Bob,
I will second JD's recommendation of TChart. I do a fair amount of
mathematical plotting, and it fits all of my needs, and more (including
zooming, printing, rescaling, log axes, and a built-in editor accessible
at run-time). *Highly* recommended.
Cheers,
Bob Penoyer wrote:
Quote
I need to draw mathematical plots. I am completely new to using
graphics under Windows, though I did a lot of it under DOS. So I have
some very basic questions.
 

Re:Objects Used for Graphing with BDS2006

Bob Penoyer < XXXX@XXXXX.COM >wrote:
Quote

Thanks, JD.
Please direct your browser to:
info.borland.com/newsgroups/guide.html
and note that over-quoting is reason to have your message
deleted or 'canceled' from the server.
Please trim your posts.
Thanks!
~ JD
 

Re:Objects Used for Graphing with BDS2006

On 13 Aug 2007 22:45:11 -0700, "JD" < XXXX@XXXXX.COM >wrote:
Quote

Bob Penoyer < XXXX@XXXXX.COM >wrote:
>
>Thanks, JD.

Please direct your browser to:

info.borland.com/newsgroups/guide.html

and resd the guide lines. Note that you are warned that
over-quoting is reaseon to have your messages canceled
(deleted) from the server. For more, see here:

tinyurl.com/2o8nef

~ JD
I officially withdraw my Thanks.
 

Re:Objects Used for Graphing with BDS2006

Bob Penoyer < XXXX@XXXXX.COM >wrote:
Quote

You didn't trim your post again!
Quote
I officially withdraw my Thanks.
That's you're choice. All I did was politely ask you to follow
the guidelines that you agreed to when you accessed this server. Too bad for you.
FTR : Your attitude has resulted in you being added to my Bozo-
Bin which means that all of your post will go unseen by my
reader. Since I visit these groups often, it means that you'll
have to wait longer for a response *and* you'll never get my
opinion or advice again. Good luck with that!
~ JD