求一个图像旋转90°的算法

hyt48079287 2009-11-26 12:14:52
Bitmap newpic;
Bitmap oldpic;

for (int y = 1; y < oldpic.Height; y++)
{
for (int x = 1; x < oldpic.Width; x++)
{
newColor = oldpic.GetPixel(oldpic.Width - x , x);
newpic.SetPixel(x, y, newColor);
}
picShow.Image = newpic;



这样貌似不行~!请高手指点
...全文
804 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
fuliang 2012-08-09
  • 打赏
  • 举报
回复
c#封装的确实很强大了,支持下bitmap1.RotateFlip()方法
w602287032 2009-12-15
  • 打赏
  • 举报
回复
厉害
zhoujk 2009-12-15
  • 打赏
  • 举报
回复
...KISS是王道
龙宜坡 2009-11-27
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 zhoujk 的回复:]
90,180,270旋转太简单了,就是XY座标互换一下位置和起点
[/Quote]


...简单的东西建立在复杂的数学理论之上
zhoujk 2009-11-26
  • 打赏
  • 举报
回复
90,180,270旋转太简单了,就是XY座标互换一下位置和起点
BATTLERxANGE 2009-11-26
  • 打赏
  • 举报
回复
mark
dwzhangyi 2009-11-26
  • 打赏
  • 举报
回复
用仿射矩阵
龙宜坡 2009-11-26
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 hyt48079287 的回复:]
我知道有旋转的方法,但是我想要的是算法....
[/Quote]


图像旋转算法原理
angel6709 2009-11-26
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 goga21cn 的回复:]
那么麻烦的!
Image img = Image.FromFile("C:\\1.jpeg");
img.RotateFlip(RotateFlipType.Rotate90FlipX);
img.Save("C:\\2.jpeg");


System.Drawing.RotateFlipType枚举
// 摘要:
    //    指定图像的旋转方向和用于翻转图像的轴。
    public enum RotateFlipType
    {
        // 摘要:
        //    指定后接水平翻转和垂直翻转的 180 度旋转。
        Rotate180FlipXY = 0,
        //
        // 摘要:
        //    指定不进行旋转和翻转。
        RotateNoneFlipNone = 0,
        //
        // 摘要:
        //    指定后接水平翻转和垂直翻转的 270 度旋转。
        Rotate270FlipXY = 1,
        //
        // 摘要:
        //    指定不进行翻转的 90 度旋转。
        Rotate90FlipNone = 1,
        //
        // 摘要:
        //    指定不进行翻转的 180 度旋转。
        Rotate180FlipNone = 2,
        //
        // 摘要:
        //    指定没有后跟水平和垂直翻转的旋转。
        RotateNoneFlipXY = 2,
        //
        // 摘要:
        //    指定不进行翻转的 270 度旋转。
        Rotate270FlipNone = 3,
        //
        // 摘要:
        //    指定后接水平翻转和垂直翻转的 90 度旋转。
        Rotate90FlipXY = 3,
        //
        // 摘要:
        //    指定后接垂直翻转的 180 度旋转。
        Rotate180FlipY = 4,
        //
        // 摘要:
        //    指定没有后跟水平翻转的旋转。
        RotateNoneFlipX = 4,
        //
        // 摘要:
        //    指定后接水平翻转的 90 度旋转。
        Rotate90FlipX = 5,
        //
        // 摘要:
        //    指定后接垂直翻转的 270 度旋转。
        Rotate270FlipY = 5,
        //
        // 摘要:
        //    指定没有后跟垂直翻转的旋转。
        RotateNoneFlipY = 6,
        //
        // 摘要:
        //    指定后接水平翻转的 180 度旋转。
        Rotate180FlipX = 6,
        //
        // 摘要:
        //    指定后接垂直翻转的 90 度旋转。
        Rotate90FlipY = 7,
        //
        // 摘要:
        //    指定后接水平翻转的 270 度旋转。
        Rotate270FlipX = 7,
    }
[/Quote]

呵呵。
hyt48079287 2009-11-26
  • 打赏
  • 举报
回复
Bitmap newpic;
Bitmap oldpic;
int newpicHeight;
int newpicWidth;
private void toolStripButton1_Click(object sender, EventArgs e)
{
newpicHeight = picShow.Image.Height;
newpicWidth = picShow.Image.Width;
newpic = new Bitmap(newpicHeight, newpicWidth);
for (int y = 1; y < oldpic.Width; y++)
{
for (int x = 1; x < oldpic.Height; x++)
{
newColor = oldpic.GetPixel(y,oldpic.Height-x);
newpic.SetPixel(x, y, newColor);
}
picShow.Image = newpic;
}
vssvss 2009-11-26
  • 打赏
  • 举报
回复
学习了
YnSky 2009-11-26
  • 打赏
  • 举报
回复
UP.楼上有了.
zhangxun829 2009-11-26
  • 打赏
  • 举报
回复
回帖是一种美德
hyt48079287 2009-11-26
  • 打赏
  • 举报
回复
我知道有旋转的方法,但是我想要的是算法....
lt42287949 2009-11-26
  • 打赏
  • 举报
回复
回帖是一种美德
dylike 2009-11-26
  • 打赏
  • 举报
回复
newpic.rote(90)
龙宜坡 2009-11-26
  • 打赏
  • 举报
回复
[DllImport("gdiplus.dll", CharSet=CharSet.Unicode, SetLastError=true, ExactSpelling=true)]
internal static extern int GdipImageRotateFlip(HandleRef image, int rotateFlipType);


龙宜坡 2009-11-26
  • 打赏
  • 举报
回复

那么麻烦的!
Image img = Image.FromFile("C:\\1.jpeg");
img.RotateFlip(RotateFlipType.Rotate90FlipX);
img.Save("C:\\2.jpeg");


System.Drawing.RotateFlipType枚举
// 摘要:
// 指定图像的旋转方向和用于翻转图像的轴。
public enum RotateFlipType
{
// 摘要:
// 指定后接水平翻转和垂直翻转的 180 度旋转。
Rotate180FlipXY = 0,
//
// 摘要:
// 指定不进行旋转和翻转。
RotateNoneFlipNone = 0,
//
// 摘要:
// 指定后接水平翻转和垂直翻转的 270 度旋转。
Rotate270FlipXY = 1,
//
// 摘要:
// 指定不进行翻转的 90 度旋转。
Rotate90FlipNone = 1,
//
// 摘要:
// 指定不进行翻转的 180 度旋转。
Rotate180FlipNone = 2,
//
// 摘要:
// 指定没有后跟水平和垂直翻转的旋转。
RotateNoneFlipXY = 2,
//
// 摘要:
// 指定不进行翻转的 270 度旋转。
Rotate270FlipNone = 3,
//
// 摘要:
// 指定后接水平翻转和垂直翻转的 90 度旋转。
Rotate90FlipXY = 3,
//
// 摘要:
// 指定后接垂直翻转的 180 度旋转。
Rotate180FlipY = 4,
//
// 摘要:
// 指定没有后跟水平翻转的旋转。
RotateNoneFlipX = 4,
//
// 摘要:
// 指定后接水平翻转的 90 度旋转。
Rotate90FlipX = 5,
//
// 摘要:
// 指定后接垂直翻转的 270 度旋转。
Rotate270FlipY = 5,
//
// 摘要:
// 指定没有后跟垂直翻转的旋转。
RotateNoneFlipY = 6,
//
// 摘要:
// 指定后接水平翻转的 180 度旋转。
Rotate180FlipX = 6,
//
// 摘要:
// 指定后接垂直翻转的 90 度旋转。
Rotate90FlipY = 7,
//
// 摘要:
// 指定后接水平翻转的 270 度旋转。
Rotate270FlipX = 7,
}
problc 2009-11-26
  • 打赏
  • 举报
回复
/// <summary>
/// method to rotate an image either clockwise or counter-clockwise
/// </summary>
/// <param name="img">the image to be rotated</param>
/// <param name="rotationAngle">the angle (in degrees).
/// NOTE:
/// Positive values will rotate clockwise
/// negative values will rotate counter-clockwise
/// </param>
/// <returns></returns>
public static Image RotateImage(Image img, float rotationAngle)
{
//create an empty Bitmap image
Bitmap bmp = new Bitmap(img.Width, img.Height);

//turn the Bitmap into a Graphics object
Graphics gfx = Graphics.FromImage(bmp);

//now we set the rotation point to the center of our image
gfx.TranslateTransform((float)bmp.Width / 2, (float)bmp.Height / 2);

//now rotate the image
gfx.RotateTransform(rotationAngle);

gfx.TranslateTransform(-(float)bmp.Width / 2, -(float)bmp.Height / 2);

//set the InterpolationMode to HighQualityBicubic so to ensure a high
//quality image once it is transformed to the specified size
gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;

//now draw our new image onto the graphics object
gfx.DrawImage(img, new Point(0, 0));

//dispose of our Graphics object
gfx.Dispose();

//return the image
return bmp;
}
wuyq11 2009-11-26
  • 打赏
  • 举报
回复
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);
}

http://topic.csdn.net/u/20090420/00/4042e404-e802-45f7-8b25-c7fbc5a81c76.html

110,544

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧