简体   繁体   中英

Creating image or graphic in C# from decimal data?

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.

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);
}

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM