Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I also believe that we all can contribute to each other's growth by sharing knowlege and experiences. I would love to take my skills and help people around the world solve problems..."

Geography

Where in the world do Tek-Tips members come from?

Paintbox image conversion to a bitmap fileHelpful Member!(2) 

stylonurus (Programmer)
6 Mar 07 21:09
I am writing a program which displays waveforms on a form. Actually I use two Paintboxes to display 8 waveforms.

The waveforms come to me via the internet from another program I wrote previously.

To display the waveforms I use a lot of Ref->Canvas->LineTo calls where Ref is the TPaintBox *

Now I would like to be able to save these waveforms as either .jpg or .gif. I searched this forum but either my search criteria sucks or its so easy nobody would bother to ask. But it's not so easy for me. I am definitely not a Builder or Graphics power user and so

Any helpful insights on how to get started would be very welcome at this time.

Thanks

Rick
Helpful Member!  2ffat (Programmer)
7 Mar 07 9:14
See if this has some source code you can use:
www.codeproject.com/bitmap/cximage.asp

It says it can be used with Borland compilers. Maybe if you sift through the code you can figure something out.

James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!

stylonurus (Programmer)
7 Mar 07 16:35
2ffat, Thanks for the link to this very interesting site.

Still I think I should be able to save a waveform created in a paintbox to a gif, bmp or jpg file using the Borland Builder C++ library.

I actually found a simple example that creates . bmp file using the following

CODE

Graphics::TBitmap* bm = new Graphics::TBitmap;
tmpW=Chart1->Width;
tmpH=Chart1->Height;

Chart1->Draw(bm->Canvas,Rect(tmpW+1,tmpH+1,2*tmpW,2*tmpH));
Chart1->BufferedDisplay=true;
bm->SaveToFile("C:\\bit.bmp");

Unfortunately the Paintbox does not have a Draw method and the PaintBox->Canvas->Draw I have not yet got to work.

Thanks for your reply. I appreciate it.

Rick


Helpful Member!  tsh73 (Programmer)
15 Mar 07 10:11
ok, I'm long forget all this stuff - but I got something work.
Probably it will help you.
Ok:
I have a PaintBox1 , on which I draw with lineTo:
Form3->PaintBox1->Canvas->LineTo(200,200);

Now I have Image1 (you probably can make it hidden?)
and on a button "Save" I do the code:

CODE

Form3->Image1->Canvas->CopyRect(
    Rect(0,0,Form3->PaintBox1->Width,Form3->PaintBox1->Height),
    PaintBox1->Canvas,
    Rect(0,0,Form3->PaintBox1->Width,Form3->PaintBox1->Height));
Form3->Image1->Picture->SaveToFile("C:\\bit.bmp");
of cource there something should be done to match size of Image (to be saved) with sice of PaintBox - but it works, I'got an image file on disk! ;))
stylonurus (Programmer)
15 Mar 07 11:22
tsh73,
Thanks for your reply. I actually tried something like this, gave up as I headed into another direction...I think it was close to what you did but I could not get it to work. I am going to try your method later today and will get back to you.. (I'm traveling today so time is limited)...

I actually ended up using a teechart or TChart. It has a built in Draw method that works. Here is some of their demo code that I used to save the Chart on a button press.

CODE

// save waveform
void __fastcall TForm3::Button2Click(TObject *Sender)
{
  Graphics::TBitmap *    bm = new Graphics::TBitmap;
  int                    tmpH,tmpW;
 
  tmpW=Chart1->Width;
  tmpH=Chart1->Height;
  bm->Width = 2*tmpW;
  bm->Height= 2*tmpH;
   
  // create chart etc;
 
  // draw chart 1  and save it to disk
  Chart1->Draw(bm->Canvas,Rect(0,0,tmpW,tmpH));
  Chart1->BufferedDisplay=true;
  bm->SaveToFile("C:\\bit2.bmp");

}

I am really impressed with this TChart although I had to spend hours with trial and error to understand a small part of the many many options it offers.

stylonurus (Programmer)
16 Mar 07 11:44
tsh73,
I was able to spend some time looking into this working piece of code. More often than not, I can get a better understanding of how a method works by seeing a working example. In the example you gave which I listed below I believe that the Canvas of Image1 will be updated from the canvas of the PaintBox. I noticed that the sizes of the rectangle coordinates are equal. Must they be? If I increase the rectangle size of the destination the resulting .bmp file is distorted. When they are equal it is perfect. Also I thought I could change the source canvas from paintbox to Form3->Canvas (which would capture all the objects visible on it). When I do this I only get some outlining labels and a few lines. In any event I really appreciate the example and given the time I will experiment more to better understand the CopyRect function. Thanks

Rick

CODE

Form3->Image1->Canvas->CopyRect(
    Rect(0,0,Form3->PaintBox1->Width,Form3->PaintBox1->Height),
    PaintBox1->Canvas,
    Rect(0,0,Form3->PaintBox1->Width,Form3->PaintBox1->Height));
Form3->Image1->Picture->SaveToFile("C:\\bit.bmp");

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close