Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 位图中的图形坐标不工作_C#_Graphics - Fatal编程技术网

C# 位图中的图形坐标不工作

C# 位图中的图形坐标不工作,c#,graphics,C#,Graphics,我一直在为我的代码的一些异常行为而挣扎 这意味着在列表中存储的坐标处绘制。它应该可以工作,因为我一直在使用相同的结构,它可以工作(唯一的区别是,上次,我在一个文件中保存坐标,然后解析它们) 绘制坐标的代码为: using (Bitmap bmp = new Bitmap(8000, 8000, System.Drawing.Imaging.PixelFormat.Format32bppPArgb)) { using (Graphics gr = Graphics.Fro

我一直在为我的代码的一些异常行为而挣扎

这意味着在列表中存储的坐标处绘制。它应该可以工作,因为我一直在使用相同的结构,它可以工作(唯一的区别是,上次,我在一个文件中保存坐标,然后解析它们)

绘制坐标的代码为:

using (Bitmap bmp = new Bitmap(8000, 8000, System.Drawing.Imaging.PixelFormat.Format32bppPArgb))
      {
       using (Graphics gr = Graphics.FromImage(bmp))
            {
             gr.FillRectangle(myWitheBrush, 0, 0, 8000, 8000);
             gr.TranslateTransform(4000, 4000);
             foreach (Vector mPD in mapsPositionsData)
             {
                 gr.FillRectangle(myBlackBrush, mPD.X, mPD.Y, 2f, 2f);
             }
             string fileName = @"\drownWholeMap" + rndm + ".png";
             loger.WriteToLog("Saving image in " + filePath + fileName + " ..."); 
             bmp.Save(filePath + fileName, System.Drawing.Imaging.ImageFormat.Png);
             loger.WriteToLog("Saved.");
             bmp.Dispose();
             gr.Dispose();
             loger.WriteToLog("");
            }
      }
代码没有给出任何错误,我检查了它是否针对列表中的每个坐标运行
mapsPositionsData
。我得到一个空的withe图像,它没有被矩形填充

此外,
mapsPositionsData
看起来像

所以我知道问题不是因为数据源为空。此外,坐标并非如图所示全部为负数,这是巧合,加上它们的范围为-4000到4000,这就是为什么我需要如此大的位图的原因。

在写之前尝试反转平移变换(在foreach之后)


@拉尔斯泰克:代码没有给出任何错误,我检查了它是否针对列表中的每个坐标运行
mapsPositionsData
。我得到一个空的withe图像,它没有被矩形填充。看起来没问题,除了处理你在using子句中创建的东西。如果你的刷子是好的,它应该工作。所有坐标都是负数吗?@LarsTech,没错。这样我就可以将最终的“地图”居中。@TaW这样我就不需要处理它们,因为一旦使用部分结束,它们就会这样做,不是吗?不,他们不是,这只是巧合,前4个是…你的代码对我有用。当您在图像编辑器中查看时,是否放大了足够的范围,因为2f x 2f是巨大画布上的一个小点。它不起作用,仍然不是单个坐标绘制。它应该起作用,但您可能需要调用gr.FlushIntention(FlushIntention.Sync);在bmp.Save()之前,确保在写入文件之前已完成所有操作。
gr.TranslateTransform(-4000, -4000);