在 C# 中从十进制数据创建图像或图形?

发布于 2024-08-14 07:48:49 字数 133 浏览 2 评论 0原文

是否可以使用小数部分不同的矢量数据创建图像或图形?当然,如果可能的话……那么如何呢?

例如:向量有两个点,其中第一个点是 {9.56, 4.1},第二个点是 {3.456789,2.12345}。

注意:精度因数字而异。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冬天旳寂寞 2024-08-21 07:48:49

您可以将矢量绘制到位图,然后保存该位图,如下所示。

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

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);
}
灯下孤影 2024-08-21 07:48:49

哦,当然。例如,Line 类将在 WPF 中绘制一条线。它为每个坐标使用两个双精度值。 X1、Y1 和 X2、Y2。

如果您的数据以十进制数据类型存储,则可以进行简单的转换。

请记住,我试图从你的问题中推断出你想要做什么。您打算如何绘制矢量形状?您的总体方法是什么?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文