Page 1 of 1
Custom drawn bitmap does not print
Posted: Wed May 03, 2006 2:18 pm
by 9345376
My problem: Custom bitmap drawn on the teechart canvas from the AfterDraw event does not print.
I have seen several other reporting a similar problem on this forum , but I haven't seen any solution to it (other that "it should work"). I therefore hope there is a possibility for a resolution now.
Here is the situation: Using BCB 6 and TeeChart v7.06 with the following code
Code: Select all
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Series1->FillSampleValues(50);
bitmap_ = new Graphics::TBitmap;
bitmap_->LoadFromFile("C:\\tmp\\logo60.bmp");
}
void __fastcall TForm1::Chart1AfterDraw(TObject *Sender)
{
Chart1->Canvas->Draw(5,5,bitmap_);
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ChartPreviewer1->Execute();
}
I am using the ChartPreviewr to show and print the chart. My bitmap shows fine on the chart and also in the print preview window, but not on paper. There is only the standard chart.
Any ideas?
Posted: Wed May 03, 2006 2:42 pm
by narcis
Hi spt,
It works fine for me here using BCB 6 and TeeChart Pro v7.07. I've created an example which I'm going to send to your forums contact e-mail address. Can you please test if the already built .exe works at your end?
Posted: Wed May 03, 2006 7:06 pm
by 9345376
The example you sent indicates what the problem is. Since you where using a much bigger bitmap than me, I was able to get something on paper, but not the whole bitmap. Only the bottom right quarter of the bitmap is printed. The rest of the image is pushed outside the printable area. Note: this is using default print options which is Landscape mode and print margins L: 15, T: 23, R: 15, B: 23; Proportional on and Smooth off.
Experimenting some more with my own example I was able to get the bitmap printed in the right position if I either print as bitmap (Smooth on in Print preview) or if I set all the print margins to 0%.
It seems that when using absolute positioning of the bitmap it shows in the right position on screen (including in the print previewer), but when printed the position is related to the actual paper size and not the box defined by the print margins. Is there any way that I can position the bitmap relative to the print margins or do you recommend to always print as bitmap? I see when I print as bitmap, dashed lines is actually printed as dashed lines which is quite useful.
Lars
Posted: Thu May 04, 2006 8:09 am
by narcis
Hi Lars,
Ok, to have the chart properly positioned you should use a position relative to the chart. i.e.: axes position, ChartRect position, etc. So you can use something like this:
Code: Select all
void __fastcall TForm1::Chart1AfterDraw(TObject *Sender)
{
Chart1->Canvas->Draw(Chart1->Axes->Left->PosAxis,
Chart1->Axes->Bottom->PosAxis-bitmap_->Height,bitmap_);
}
Posted: Thu May 04, 2006 10:34 am
by 9345376
Thanks for the help. I ended up using ChartRect as I wanted to position the bitmap outside the plot area and not rely on axis that may or may not be active. I noticed that axes that are not connected to a series return a PosAxis of 0.
So the conclusion on this is to always draw using position relative to ChartRect or PosAxis to get the custom drawing in the right position both on screen and on print. This should be a FAQ.
Thanks
Lars
Posted: Thu May 04, 2006 10:38 am
by narcis
Hi Lars,
I'm glad to hear you could make this work. I've written down your FAQ's suggestion and we will consider it when reviewing the FAQ section.