老师让我们思考如何在C#的程序中浏览浏览单张图片时对对图片进行顺时针或逆时针旋转?还有在浏览单张图片时可以将其删除、可以以全屏的方式浏览单张图片,这些都要怎么做,谁能教教我,谢谢!!!

解决方案 »

  1.   

    这些都很简单。旋转:
    private Bitmap rotateImage(Bitmap b, float angle) {     //create a new empty bitmap to hold rotated image     Bitmap returnBitmap = new Bitmap (b.Width, b.Height);     //make a graphics object from the empty bitmap     Graphics g = Graphics .FromImage(returnBitmap);     //move rotation point to center of image     g.TranslateTransform((float )b.Width / 2, (float )b.Height / 2);     //rotate     g.RotateTransform(angle);     //move image back     g.TranslateTransform(-(float )b.Width / 2, -(float )b.Height / 2); } 
    删除:
    System.IO.File.Delete()
    全屏就是将窗口边框去掉,最大化,再拉伸图片(注意考虑横宽比例)总之都是极其简单的问题。
      

  2.   

    两种方法都可以!
    Graphics.TranslateTransform 
    string filePath =@"C:\a.jpg"; 
    using (Bitmap bm = new Bitmap(500,500)) 

      using (Graphics g = Graphics.FromImage(bm)) 
      { 
        g.Clear(Color.Wheat); 
         g.TranslateTransform(0, 0, MatrixOrder.Prepend); 
        g.RotateTransform(45); 
        FontFamily ff = new FontFamily("宋体"); 
        Font f =new Font(ff,10); 
        Brush b = new SolidBrush(Color.Black); 
        StringFormat sf = new StringFormat(); 
        g.DrawString("", f, b, new PointF(10, 10), sf); 
        g.DrawString("", f, b, new PointF(10, 10 + 30 + 10), sf); 
      } 
      bm.Save(filePath, ImageFormat.Jpeg); 
    }方法二似乎更加简单!
    Image img = Image.FromFile("C:\\1.jpeg");
    img.RotateFlip(RotateFlipType.Rotate90FlipX);  //System.Drawing.RotateFlipType枚举
    img.Save("C:\\2.jpeg");