当前位置:编程学习 > C#/ASP.NET >>

这个图片如何旋转啊,摸索了好几天,求高人

我想拉动旋转滚动条,主窗口A图片旋动,怎么实现哦。 --------------------编程问答--------------------
public void AddCoverImage(String path)
        {
            if (_Item != null)
            {
                CoverImage ci = new CoverImage();
                ci.Path = path;
                FileInfo file = new FileInfo(path);
                ci.Name = file.Name;

                Single width = 90.0F;
                Single height = 90.0F;

                Single left = 20.0F;
                Single top = 20.0F;

                width /= this.Width;
                left /= this.Width;
                height /= this.Height;
                top /= this.Height;

                ci.Region = new RectangleF(left, top, width, height);

                _Item.CoverImageList.Add(ci);
                DraggingObjext = ci;           

                this.Invalidate();
            }
        }

小图标是通过这个函数添加进imagebox里的 --------------------编程问答-------------------- 这个功能使用 GDI+ 好像比较容易实现 --------------------编程问答-------------------- 具体怎么实现哦,初学C#,但项目又需要快速实现这个功能,要不然就慢慢学了,请赐教哇 --------------------编程问答-------------------- http://blog.sina.com.cn/s/blog_636048bc0100h3c4.html --------------------编程问答-------------------- @dongxinxi 感谢你的回复哦,不过像C#图片旋转的找了好多,都不能用,比方说你找的这个,它是要指定图片的Image oldImage = pictureBox.Image;pictureBox.Image = Utilities.RotateImage(img, (float) angle.Value);这两句就不能换成我的,因为不知道用哪个对像上有image属性,老是提示错误。 --------------------编程问答-------------------- Image是图片抽象类,那个例子是通过PictureBox控件加载的图片
Image oldImage = pictureBox.Image;
pictureBox.Image = Utilities.RotateImage(oldImage, (float) angle.Value);
他那里变量名写错了,你应该可以看出来

另外Image还可以从文件或者流图片中读取,也可以自己构造
1.Image.FromFile(path)
2.Image.FromStrem(stream)
3.bitmap = new System.Drawing.Bitmap(towidth, toheight);
using(g = System.Drawing.Graphics.FromImage(bitmap))
{
    g.DrawImage(另一个Image, 位置参数);
} --------------------编程问答-------------------- (float) angle.Value是需要旋转的角度,你可以直接传数据
他的g.RotateTransform(360 - angle);这一句可以根据你的需要来改
你可以改成,第二个参数控制旋转方向
g.RotateTransform(angle, System.Drawing.Drawing2D.MatrixOrder.Append); --------------------编程问答-------------------- 图片已经添加了,是通过按钮点击,选择文件添加进来的,代码如下:
 private void tsbDecoration_Click(object sender, EventArgs e)
        {
            AddDecoration();
        }

        private void AddDecoration()
        {
            openFileDialog2.Filter = "装饰图片(*.png)|*.png";
            openFileDialog2.InitialDirectory = Application.StartupPath + "\\Image\\";

            if (openFileDialog2.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                String path = openFileDialog2.FileName;

                imagebox1.AddCoverImage(path);
            }        
        }

AddCoverImages函数如下:
public void AddCoverImage(String path)
        {
            if (_Item != null)
            {
                CoverImage ci = new CoverImage();
                ci.Path = path;
                FileInfo file = new FileInfo(path);
                ci.Name = file.Name;
 
                Single width = 90.0F;
                Single height = 90.0F;
 
                Single left = 20.0F;
                Single top = 20.0F;
 
                width /= this.Width;
                left /= this.Width;
                height /= this.Height;
                top /= this.Height;
 
                ci.Region = new RectangleF(left, top, width, height);
 
                _Item.CoverImageList.Add(ci);
                DraggingObjext = ci;           
 
                this.Invalidate();
            }
        }

两个滚动条,一个是改变大小的,一个是旋转的
private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
        {
            Single width = hScrollBar1.Value * 1.0F / BuddyFrm.imagebox1.Width;
            Single height = hScrollBar1.Value * 1.0F / BuddyFrm.imagebox1.Height;
            Single a = CoverImage.Region.Left ;
            Single b = CoverImage.Region.Top ;
           // textBox1.Text = Convert.ToString(a) + "-" + Convert.ToString(b) + "-" + Convert.ToString(width) + "-" + Convert.ToString(height) + "-" + Convert.ToString(BuddyFrm.imagebox1.Width);
            CoverImage.Region = new RectangleF(a, b, width, height);

            BuddyFrm.imagebox1.Refresh();
        }

        private void hScrollBar2_Scroll_1(object sender, ScrollEventArgs e)
        {
}

hScrollBar1是改变大小的,可以实现,但hScrollBar2就不知道怎么旋转了,不知道我表达清楚没有。 --------------------编程问答--------------------
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,