关于 .net:C# /GDI 图形缩放(画线) | 珊瑚贝

C# /GDI Graphics Scaling (Drawline)


我正在写一些东西来从矢量格式文件创建小的位图预览。从文件中,我有一个(大)线坐标列表。我想要做的是缩放它以使其适合固定宽度的图像(96×96)。我之前一直在以全尺寸绘制位图,然后只是将其调整为 96×96,但由于需要动态创建缩略图,结果证明速度不够快(而且这是一种非常愚蠢的方法首先!)。现在我只想缩放所有坐标,就好像原始尺寸是 96×96 一样,删除所有相互重叠的点,这应该会大大提高性能。

我是任何和所有 .NET 图形/GDI 东西的绝对新手,第一个版本非常简单(代码如下)。我想知道图形库(或其他地方)中是否有一些东西可以做到这一点,而我不必遍历所有点并对每个点进行数学运算。

图形/GDI 大师能否为我指明正确的方向(或让我知道没有方向)?我正在使用 C#,.NET 框架目标是好的。

到目前为止,它非常简单(tmpblocks 是一个点数组):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Bitmap DrawArea;
Graphics xGraph;

DrawArea = new Bitmap(64, 64);
// ^- this is GetWidth() and GetHeight() when drawing the full file at full size

xGraph = Graphics.FromImage(DrawArea);

for (int i = 0; i < tmpblocks.Count; i++)
{
 if (tmpblocks[i].stitches.Length > 1)
 {
 Pen tempPen = new Pen(tmpblocks[i].color, 1.0f);
 tempPen.StartCap = System.Drawing.Drawing2D.LineCap.Round;
 tempPen.EndCap = System.Drawing.Drawing2D.LineCap.Round;
 tempPen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
 xGraph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
 xGraph.DrawLines(tempPen, tmpblocks[i].stitches);
 }
}

对于缩略图,我只需使用 .GetThumbnail 方法缩放生成的位图。真的很慢,虽然(显然)……


您可以使用 Graphics.ScaleTransform(float sx, float sy) 来完成此操作。

你可以从:TargetWidth / SourceWidth 得到 sx
和 sy 来自:TargetHeight / SourceHeight

其中目标由您的目标图像大小定义,源是您的源图像大小。

  • 我看到并尝试了它,但我得到的只是一个白色的 BMP,角落里有几行..
  • 我不确定为什么需要使用平移变换,除非矢量文件和图形设备之间存在一些其他坐标系差异,即 y 指向哪个方向。但是,如果此答案有帮助,我将非常有义务将其标记为已回答。


来源:https://www.codenong.com/7208342/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9071.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?