Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Paintbox image conversion to a bitmap file 2

Status
Not open for further replies.

stylonurus

Programmer
Jun 7, 2006
19
US
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
 
See if this has some source code you can use:

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


James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
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


 
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! ;))
 
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.

 
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");
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top