views:

148

answers:

2

Is it possible to create an image or graphic using vector data that has decimal components that vary? And, of course, if its possible... then how?

For example: a vector has two points where point one is {9.56, 4.1} and point two is {3.456789,2.12345}.

Note: the precision varies from number to number.

A: 

Oh, sure. For example, the Line class will draw a line in WPF. It uses two doubles for each coordinate. X1, Y1 and X2, Y2.

If your data is stored in the decimal datatype, you can do a simple cast.

Keep in mind, I'm trying to extrapolate what you're trying to do from your question. How are you planning to draw your vector shapes? What's your overall approach?

Randolpho
Um.. Not sure what you mean by "my approach". But I"m using C# to solve a specific problem (don't want to discuss on here due to IP issues). I import my initial vector data, perform some operations whose output are some other vectors (possible different color). And I want to be able to visualize the output by viewing a jpg or png.
Sean Ochoa
+3  A: 

You can draw vectors to a bitmap and then save that bitmap as follows.

using System.Drawing;
using System.Drawing.Imaging;
.
.  
.
using (Bitmap bmp = new Bitmap(10, 10))
{
    using (Graphics g = Graphics.FromImage(bmp))
    {
        g.Clear(Color.White);
        g.DrawLine(Pens.Black, new PointF(9.56f, 4.1f), new PointF(3.456789f, 2.12345f));
    }
    bmp.Save(@"c:\myimage.jpg", ImageFormat.Jpeg);
}
Dude... That's EXACTLY what I was looking for. Thank you!!!
Sean Ochoa
+1 for the no nonsense code snippet that features the asker's sample data.
Paul Sasik
Even though this solution worked for a small set of the geo data, it started having problems when dealing with larger than normal resolutions, and more than 10000 vectors.
Sean Ochoa
@Sean Ocha - You didn't mention those requirements in your post. A simple solution mapping the coordinates to a viewport and culling the ones that are too big or too small for the viewport would probably work well.