Как отцентрировать это изображение - PullRequest
0 голосов
/ 19 марта 2020

У меня есть изображение, которое выглядит следующим образом. У меня есть заостренное изображение, которое выглядит хорошо, а затем я должен нарисовать зеленое изображение поверх заостренного изображения. Идея состоит в том, чтобы нарисовать зеленое изображение в центре заостренного изображения. У меня есть некоторые проблемы с этим.

     var shipImageOffset = new PointF(0, 0);
     using (var bmp = new Bitmap(_shipImage))
     using (var image = ImageUtilities.RotateImage(
        bmp,
        (float)ShipHeading,
        new PointF(this.Width / 2, this.Height / 2),
        shipImageOffset,
        this.Width,
        this.Height))
     {

        e.Graphics.DrawImage(image, new PointF(0,0));

     }


     //paint the green pointer image
     if (_windImageRepo.TryGetValue(needleSpeed, out var windImage))
     {
        //need to figure out the origin point - the origin point is the center of the long rectangle
        //at the bottom
        var center = new PointF(windImage.HorizontalResolution, windImage.VerticalResolution);
        using (var bmp = new Bitmap(windImage))
        {

           for (int x = 0; x < bmp.Width; x++)
           {
              for (int y = 0; y < bmp.Height; y++)
              {
                 var color = bmp.GetPixel(x, y);
                 if (color != Color.FromArgb(0))
                 {
                    bmp.SetPixel(x, y, System.Drawing.Color.LimeGreen);
                 }
              }
           }

           var windImageOffset = new PointF(0,0);
           using (var image = ImageUtilities.RotateImage(
               bmp,
               (float)WindHeading,
               new PointF(this.Width / 2, this.Height / 2),
               windImageOffset,
               this.Width,
               this.Height))
           {

              //This is your image from the pictureBox1
              Bitmap img = new Bitmap(_shipImage);

              // I am targeting the middle of the image, Your case would be the binarized image
              Point index = new Point(img.Size.Width / 2, img.Size.Height / 2);

                              e.Graphics.DrawImage(image,Center(_shipImage));

           }


        }

     }

        base.OnPaint(e);
    }

Цель состоит в том, чтобы получить зеленый указатель в середине другого изображения. Не повезло.

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...