Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I'm trying to draw a custom dashed line, but I want to put an image inside of this dashed line. The orientation of my line is variable.

The aircraft in the middle of the line is an image. I don't want to draw a line, draw the image, and draw another line, because i've got a dynamic angle calculated with an arcTan. The X length is fix and known, the Y red Line can change.

What I have tried:

I tried to draw a line, draw the image, and draw another line but it's not perfect, because of the variable angle.

That's a part of my code :

Image aircraftLogo = Image.FromFile(PATH);//aircraft Logo

decimal arctanValue = Decimal.Divide(X, Y);
                double aircraftLogoRotation = -Math.Atan(Convert.ToDouble(arctanValue)) * (180 / Math.PI);

                float moveX = aircraftLogo.Width / 2f  + X;
                float moveY = aircraftLogo.Height / 2f + Y;
                g.TranslateTransform(moveX, moveY);
                g.RotateTransform(Convert.ToSingle(aicraftLogoRotation));
                g.TranslateTransform(-moveX, -moveY);
                g.DrawImage(aicraftLogo, X, Y, width, Height);
                g.ResetTransform();


I'm a beginner in C#.
Thanks for your help.
Mineodo
Posted
Updated 12-Mar-20 3:16am
v5

1 solution

You know the rotation of the aircraft, you know the location you are going to put it - you've worked those out. And you know how big it is.

So draw the whole line as one item, then draw a background colour over the "middle bit" where you are going to put the plane to erase a chunk of the line, then draw the plane.
Result: a dashed line with a plane in it...

The other solution is to draw your lines horizontally onto a Bitmap, draw the plane horizontally between them, then then rotate that image to draw it onto your graphics context.
 
Share this answer
 
Comments
Maciej Los 12-Mar-20 8:10am    
5ed!
Mineodo68 12-Mar-20 9:14am    
It works, thanks a lot !
OriginalGriff 12-Mar-20 9:28am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900