Page 1 of 1
Drawing canvas backimage
Posted: Fri Sep 16, 2011 8:35 pm
by 9347200
Hi,
This is my issue, I am using the imagetool from teechart tools menu to draw a image on the background. However one issue is there is no way to specify where to draw the image, i.e the co-ordinates or starting point. The image tool just draws a image associated with a series. Is there a way to specify the limits from where to start drawing ?
Now I see that there is another method associated with the canvas called draw, However draw needs the image as a LPUNKNOWN type, How do I generate this type ?
Tchartctrl1.GetCanvas().Draw(x,y,(LPUNKNOWN) ??);
My requirement is to be able to exactly coincide the background image with respect to a series, how can I achieve this ?
Thanks,
Re: Drawing canvas backimage
Posted: Mon Sep 19, 2011 8:38 am
by narcis
Hi ActiveX7,
This is my issue, I am using the imagetool from teechart tools menu to draw a image on the background. However one issue is there is no way to specify where to draw the image, i.e the co-ordinates or starting point. The image tool just draws a image associated with a series. Is there a way to specify the limits from where to start drawing ?
You could try custom drawing on the chart canvas assigning an image to the canvas.brush and draw a rectangle in the position you wish. This should be done in TChart's OnAfterDraw event or if you need the image being painted behind the series you could try with other chart or series drawing events.
Now I see that there is another method associated with the canvas called draw, However draw needs the image as a LPUNKNOWN type, How do I generate this type ?
Tchartctrl1.GetCanvas().Draw(x,y,(LPUNKNOWN) ??);
LPUNKNOWN is the same as "IUnknown *", or a pointer to an object which supports the IUnknown interface. This interface is the base class for every COM and ActiveX class. You would use it to pass a reference to a COM or ActiveX object when you don't know or don't care what interfaces it actually supports. It is for reference counting and finding other interfaces an object supports.
I'm sorry but I'm not a Visual C++ specialist. Probably searching on the internet you'll find usage examples. Alternatively you can use canvas' AssignImage and Rectangle methods:
Code: Select all
m_Chart1.GetCanvas().GetBrush().AssignImage(ImageHandle);
m_Chart1.GetCanvas().Rectangle(Left, Top, Right, Bottom);
My requirement is to be able to exactly coincide the background image with respect to a series, how can I achieve this ?
This will slightly vary depending on the series style you are using but you should calculate series screen coordinates using its CalcXPos and CalcYPos methods.
Re: Drawing canvas backimage
Posted: Mon Sep 19, 2011 9:05 pm
by 9347200
m_Chart1.GetCanvas().GetBrush().AssignImage(ImageHandle);
The assign image method above takes a long (ImageHandle) as a parameter, is this only meant for images in the resource file ? I want to load image from a file. Do you have an example ?
Thanks,
Re: Drawing canvas backimage
Posted: Tue Sep 20, 2011 8:50 am
by narcis
Hi Activex7,
To load images from a file you can use LoadImage method:
Code: Select all
m_Chart1.GetCanvas().GetBrush().LoadImage(fileName);
An example can be found
here.
Re: Drawing canvas backimage
Posted: Tue Sep 20, 2011 5:04 pm
by 9347200
Hi Narcis.
Thanks for your help in this issue. I have a couple of questions
a)When I use the canvas to draw a image, I cannot zoom it ? like the behavior of the chartimage tool ?
b) Also the image drawn using the canvas is drawn over the series, Can I make to draw below the series ?
Thanks,
Re: Drawing canvas backimage
Posted: Wed Sep 21, 2011 7:08 am
by narcis
Hi Activex7,
a)When I use the canvas to draw a image, I cannot zoom it ? like the behavior of the chartimage tool ?
I'm afraid not.
b) Also the image drawn using the canvas is drawn over the series, Can I make to draw below the series ?
You could try using chart's OnBeforeDraw or OnBeforeDrawSeries events instead of OnAfterDraw.
Re: Drawing canvas backimage
Posted: Wed Sep 21, 2011 3:19 pm
by 9347200
Thanks narcis, So for my purposes I would have to stick with the chartimage tool.
The question I have is, what kind of image manipulation does it take to make a image fit well, if the series is a point series. Also can I get the resolution from Teechart ? I am guessing if I can get the resolution/width of the chart and can modify the image accordingly I might be able to get a more better fit ?
For example, say if have a series (point) with some data points and then I have a image with bubbles in it, where each of the bubbles should coincide with a point from the series, I am using the chart image tool as I want the zoom functionality, what can I do to make this image fit better ? assuming the image and series are in the same boundaries.
Thanks,
Re: Drawing canvas backimage
Posted: Thu Sep 22, 2011 8:44 am
by narcis
Hi Activex7,
The question I have is, what kind of image manipulation does it take to make a image fit well, if the series is a point series. Also can I get the resolution from Teechart ? I am guessing if I can get the resolution/width of the chart and can modify the image accordingly I might be able to get a more better fit ?
You can get
ChartRect boundaries but you won't be able to resize the Image tool unless you format the image outside TeeChart and add it already formated.
For example, say if have a series (point) with some data points and then I have a image with bubbles in it, where each of the bubbles should coincide with a point from the series, I am using the chart image tool as I want the zoom functionality, what can I do to make this image fit better ? assuming the image and series are in the same boundaries.
An alternative could be use ImagePoint series where you can set a pointer image and a point series on top with same values. Would this fit your needs?