winforms - How to move a certain part of a picture box using Visual Studio c# -


i move part of picture box move part. can move left right want move tip of only.

    private float angle = 0.0f;     image image;      private void form1_keydown(object sender, keyeventargs e)     {         if (e.keycode == keys.right) angle += 1;         else if (e.keycode == keys.left) angle -= 1;          int = picturebox1.location.x;         int b = picturebox1.location.y;          if (e.keycode == keys.right) += 5;         else if (e.keycode == keys.left) -= 5;          picturebox2.location = new point(a, b);          rotateimage(picturebox1, image, angle);     }      private void rotateimage(picturebox pb, image img, float angle)     {         //store our old image can delete         image oldimage = pb.image;         pb.image = rotateimage(img, angle);          if (oldimage != null)             oldimage.dispose();     }      public static bitmap rotateimage(image image, float angle)     {         return rotateimagefinal(image, new pointf((float)image.width / 2, (float)image.height / 2), angle);     }      public static bitmap rotateimagefinal(image image, pointf offset, float angle)     {         //create new empty bitmap hold rotated image         bitmap rotatedbmp = new bitmap(image.width, image.height);         rotatedbmp.setresolution(image.horizontalresolution, image.verticalresolution);          //make graphics object empty bitmap         graphics g = graphics.fromimage(rotatedbmp);          //put rotation point in center of image         g.translatetransform(offset.x, offset.y);          //rotate image         g.rotatetransform(angle);          //move image         g.translatetransform(-offset.x, -offset.y);          //draw passed in image onto graphics object         g.drawimage(image, new pointf(0, 0));          return rotatedbmp;     }      private void form1_load(object sender, eventargs e)     {   //just store address of 'arrow' image.         string path = directory.getcurrentdirectory();         image = new bitmap(path + "/img/arrow.bmp");     }  

a ps of object want tilt, i'm interested in fixating bottom part meanwhile moving top http://imgur.com/h2ic2g7

i interested in question , decided spend time search more image rotation in c#. here goes result.

    private float angle = 0.0f;     image image;      private void form1_keydown(object sender, keyeventargs e)     {         if (e.keycode == keys.right) angle+=1;         else if (e.keycode == keys.left) angle-=1;          int = ballpb.location.x;         int b = ballpb.location.y;          if (e.keycode == keys.right) += 5;         else if (e.keycode == keys.left) -= 5;          ballpb.location = new point(a, b);          rotateimage(arrowpb, image, angle);     }      private void rotateimage(picturebox pb, image img, float angle)     {         //store our old image can delete         image oldimage = pb.image;         pb.image = rotateimage(img, angle);          if (oldimage != null)             oldimage.dispose();     }      public static bitmap rotateimage(image image, float angle)     {         return rotateimagefinal(image, new pointf((float)image.width / 2, (float)image.height / 2), angle);     }      public static bitmap rotateimagefinal(image image, pointf offset, float angle)     {         //create new empty bitmap hold rotated image         bitmap rotatedbmp = new bitmap(image.width, image.height);         rotatedbmp.setresolution(image.horizontalresolution, image.verticalresolution);          //make graphics object empty bitmap         graphics g = graphics.fromimage(rotatedbmp);          //put rotation point in center of image         g.translatetransform(offset.x, offset.y);          //rotate image         g.rotatetransform(angle);          //move image         g.translatetransform(-offset.x, -offset.y);          //draw passed in image onto graphics object         g.drawimage(image, new pointf(0, 0));          return rotatedbmp;     }      private void form1_load(object sender, eventargs e)     {   //just store address of 'arrow' image.         string path = directory.getcurrentdirectory();         image = new bitmap(path + "\\img\\arrow.png");     } 

the credits logic goes musicmonkey5555 (http://www.codeproject.com/articles/58815/c-image-picturebox-rotations). can download source code link in case above code isn't clear. luck!


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -