图片绕圆形轨迹移动

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ImageProcessing
{
    public partial class Move : Form
    {
        Bitmap btm = new Bitmap("\small.jpg");
     

        public Move()
        {
            InitializeComponent();
        }

 

        protected void OnPaint()
        {
            Pen myPen = new Pen(ForeColor, 2);     //定义画笔
            float radius = (float)(Width / 5);               //半径
            const int partitionNum = 360;                  //角度变化360次
            float angleUnit = (float)(2 * Math.PI / partitionNum); //角度转为弧度
            int[] circleX = new int[partitionNum];     //横坐标数组
            int[] circleY = new int[partitionNum];     //纵坐标数组

            //int originX = ClientSize.Width / 2;
            int originX = 70;                                      //圆心横坐标
            //int originY = ClientSize.Height / 2;
            int originY = 70;                                      //圆心纵坐标

            for (int i = 0; i < partitionNum; i++)        //对横、纵坐标赋值
            {
                circleX[i] = (int)(radius * Math.Cos(i * angleUnit)) + originX;
                circleY[i] = (int)(radius * Math.Sin(i * angleUnit)) + originY;
            }
            for (int i = 0; i < partitionNum – 1; i++)
            {
                for (int y = 0; y < 200000; y++) { }        //延时
                pictureBox1.Size = btm.Size;
                pictureBox1.Image = btm;
                pictureBox1.Location = new Point(circleX[i++], circleY[i++]);

                //从该处(i处)的横纵坐标移动到下一处(i+1处)的横纵坐标
                this.Refresh();
            }                                                           
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            OnPaint();
        }
    }
}

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s