1

I want to rotate a bitmap image constantly but the array of four elements of points that I created doesn't fit in this method. drawimage(image,points,srcrectangle,Graphicsunit).

I was reading microsft document about drawimage method and It says that it will work for 3 points(paralellogram). So I tried with 3 points, and It works as microsoft document says. But I need these four elements, perhaps I'm wrong , can someone just tell me how this method works?

    public override void dibujar(Graphics area, Bitmap imagen)
    {

        radio = Math.Sqrt(Math.Pow(ancho, 2) + Math.Pow(largo, 2)) / 2;
        Rectangle porcion = new Rectangle(indicex * ancho, indicey * largo, ancho, largo);

        Point p1 = new Point(x + (int)(radio * Math.Sin(Math.PI * angulo / 180)), y+(int)(radio * Math.Cos(Math.PI * angulo / 180)));
        Point p2 = new Point(x + ancho + (int)(radio * Math.Sin(Math.PI * (angulo-90) / 180)), y + (int)(radio * Math.Cos(Math.PI * (angulo - 90) / 180)));
        Point p3 = new Point(x + (int)(radio * Math.Sin(Math.PI * (angulo - 180) / 180)), y - largo + (int)(radio * Math.Cos(Math.PI * (angulo - 180) / 180)));
        Point p4 = new Point(x + ancho + (int)(radio * Math.Sin(Math.PI * (angulo - 270) / 180)), y - largo + (int)(radio * Math.Cos(Math.PI * (angulo - 270) / 180)));
        Point[] points = {  p2, p3, p4 }; // Get all points in one array
        area.DrawImage(imagen, points, porcion, GraphicsUnit.Pixel);
        if (angulo == 0)
        {
            angulo = 360;
        }
        else
        {
            angulo--;
        }
        x += dx;

    }

This method throw NotimplementedException when my array is of four elements

  • Hi Sebastian, welcome to SO! Your method calls should always match one of the existing method definitions. Does the overload method `DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit)` fit your requirement by changing those points to coordinates and dimensions? or you could create a destination rectangle, `DrawImage(Image, Rectangle, Rectangle, GraphicsUnit)`? https://learn.microsoft.com/en-us/dotnet/api/system.drawing.graphics.drawimage – yoogeeks Feb 09 '19 at 19:44
  • @yoogeeks: He seems to be using this overload: `DrawImage(Image, Point[], Rectangle, GraphicsUnit)` - https://learn.microsoft.com/en-us/dotnet/api/system.drawing.graphics.drawimage?view=netframework-4.7.2#System_Drawing_Graphics_DrawImage_System_Drawing_Image_System_Drawing_Point___System_Drawing_Rectangle_System_Drawing_GraphicsUnit_ – Chris Feb 09 '19 at 19:51
  • Is this NotImplementedException being thrown by the call to DrawImage? Can you provide a full stack trace and the exact message that is shown with this exception? Also I'm a bit confused because you say "So I tried with 3 points, and It works as microsoft document says. " and then later "This methot throw NotimplementedException when my array is of three elements" – Chris Feb 09 '19 at 19:54
  • @Chris When there are 3 elements in the array of points, it works fine, but If I put 4 elements, throw the NotImplementedException.Sorry, I already edited it. – Sebastian Julon Chamana Feb 09 '19 at 20:04
  • So your last line of the question should say "four elements"? I'm also unclear what your four points are. You only need three points to define a parallelogram so your fourth point is either redundant or is not part of a parallelogram in which case its not clear what you are attempting to do since that method *requires* three points, not four. – Chris Feb 09 '19 at 20:10
  • 2
    @Chris if they require 4 points it simply means resulting shape is not always parallelogram. It is not supported by `DrawImage` but there are plenty of existing questions about it (I picked couple as duplicates). If those would be not enough OP at least have some search terms to investigate like "perspective warp". – Alexei Levenkov Feb 09 '19 at 20:20

0 Answers0