Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Can't make Picture type CNiAnnotations transparent

I'm using Measurement Studio 8 in Visual Studio 6 (C++) and am trying to use a CNiAnnotation to place an image (bmp) on my dot plot graph (CNiGraph).  Unfortunately when I do this it hides any data points in it's area.  It also hides the grid in it's area, but this is less critical.
 
I've tried the CNiAnnotation.Shape.Image.Transparent (and TransparentColor) properties but they don't seem to help.  Even worse, they seriously degrade the image quality.
 
I am using multiple plots (CNiPlot) on this graph, one for the data and another to hold annotations.  Since I'm told the order of the plots is important the annotation plot is the first one added to the graph during it's initialization.
 
Any advice or ideas would be appreciated.  Thankyou.
 
Here is my (simplified) code.
 

// Create the image. 

CNiAnnotation image = m_graph.Annotations.Add();

image.SetBuiltinStyle(CNiAnnotation::Picture);

image.Shape.Type = CNiShape::Picture;

image.Plot = m_StructurePlot;   // The first plot added to the graph.

image.CoordinateType = CNiAnnotation::AxesCoordinates;

 

// Hardcode the location for testing purposes.

CNiReal64Vector xt(2), yt(2);

xt[0] = 2;

xt[1] = 12;

yt[0] = 2;

yt[1] = 12;

image.Shape.XCoordinates = xt;

image.Shape.YCoordinates = yt;

 

image.Shape.Image.Url = structure.m_GraphicFile;

image.Shape.Image.Stretch = true;

image.Shape.Image.Transparent = true;               

image.Shape.Image.TransparentColor.SetBlue(255);

image.Shape.Image.TransparentColor.SetGreen(255);

image.Shape.Image.TransparentColor.SetRed(255);

 

image.Shape.Image.Reload();

0 Kudos
Message 1 of 7
(8,001 Views)

Hi ADombroski,

What you are noticing when trying to set the image to transparent is actually the correct behavior. The transparent property actually only makes one color transparent. You can use the Transparent and TransparentColor properties to create transparent regions within a bitmap, icon, or metafile. When the graph draws the image, it does not draw any pixels that are the color of the Transparent color. Thus, whatever graphics are underneath the image show through. So, first you should choose the color you want to make transparent and then set the transparent property to true.

I assume you actually have a multi-colored image, which is why you are seeing the image quality decrease. The quality is not actually decreasing; rather, it is missing a few colors.

I'm a little confused why you are trying to add a image as an annotation and then make it transparent. If you don't want the image to appear, you could use the CNiAnnotation or CNiImage Visible property which should be easier to control.

Regards,

Matt M.
NI

0 Kudos
Message 2 of 7
(7,993 Views)

Hi Matt,

Thanks for the response.  Actually I'm not all that fixated on the 'transparent' feature, but was looking into it as a means to solve my problem.  The problem is that I have a 2D point plot graph that I would like to add a picture to.  The picture represents a real-world structure (like a metal plate or bar).  The image annotation seems perfect for this because it will pan/zoom/stretch/etc with the data.  Unfortunately it also covers up (hides) the data points (dots).  Basically I want to see the dots drawn on top of the image, not the other way around.  If possible, i'd like to have the grid drawn on top of it as well.

There are several plots on this graph.  The first one added to the graph is the one containing the annotation.  Ones added later hold the data points.

Is there any way to accomplish this?

Thanks.

0 Kudos
Message 3 of 7
(7,987 Views)
Hi Adombroski,
 
I have been playing with this quite a bit and I can't find a way to make change the order of the image and the plots in Visual Studio 6.0. In .NET, Microsoft opened up a lot more, allowing us to have predraw events that would allow us to create annotations underneath the plots; however, this is not available in Visual Studio 6.
 
As a workaround: for your initial plot, you could try using the CWGraph.PlotAreaImage property. This would plot an image in the background, underneath your plots and your grid. The problem is that this image does not zoom or pan. To get around this, you could catch a change event on the graph for anytime a zoom occurs. You could then get the new range and generate a smaller part of the image that you want to show.
 
Regards,
 
Matt M.
NI
0 Kudos
Message 4 of 7
(7,971 Views)

Hi Matt,

Thanks for your help.  This is dissapointing though, as I am very impressed with the versatility of annotations.  If necessary I will look into doing it by hand as you suggest.

I'd like to take one final crack at annotations though, using the Transparent properties.  If my images were basically stick figures on a white background, I could make the color white transparent and achieve much of what I'm looking for.  Unfortunately I can't seem to make any color other than black transparent.  Perhaps I'm doing something wrong, but this code does not seem to work.

                image.Shape.Image.Transparent = true;
                image.Shape.Image.TransparentColor.SetBlue(255);
                image.Shape.Image.TransparentColor.SetGreen(255);
                image.Shape.Image.TransparentColor.SetRed(255);

Regardless of the color I set in the code above, black (0,0,0) is always transparent (nothing else is transparent).  For this test I am using a simple 2 color bitmap with only black (0,0,0) and white (255,255,255) used.  Am I missing something?

Thanks,

Andrew

 

 

 

 

0 Kudos
Message 5 of 7
(7,965 Views)
Hi Andrew,
 
I think you'll want to set an actual color value to the TransparentColor. You could try using this line to make white transparent:
 
image.Shape.Image.TransparentColor = 0xFFFFFF
Where 0xFFFFFF is the hex code for white. Only the last color set to the transparent color property will actually be transparent, meaning if you had three colors (say black, white and red) and you had these two lines:
 
image.Shape.Image.TransparentColor = 0xFFFFFF
image.Shape.Image.TransparentColor = 0x0000FF
 
Only the red color would be transparent.
 
I've tried this out and got it to work on my system.
 
Regards,
 
Matt M.
NI
0 Kudos
Message 6 of 7
(7,962 Views)

Matt,

That works.  If all we need are thin color-on-white line drawings then this will work out for us.  Thanks for your help.

Regards,

Andrew

0 Kudos
Message 7 of 7
(7,941 Views)