-4
Q
旋转并用C#
A
回答
1
这里有一个方法,你可以用它来旋转在C#中的图像:
/// <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;
}
您可以使用Graphics.DrawImage来绘制裁剪图像到图形对象来自位图。
Rectangle cropRect = new Rectangle(...);
Bitmap src = Image.FromFile(fileName) as Bitmap;
Bitmap target = new Bitmap(cropRect.Width, cropRect.Height);
using(Graphics g = Graphics.FromImage(target))
{
g.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height),
cropRect,
GraphicsUnit.Pixel);
}
相关问题
- 1. 旋转JLabel并读取旋转值
- 2. Swift/Objective c - 当场旋转/旋转CAShapeLayer
- 3. 阵列:左旋转用C
- 4. ggplot geom_bar - '旋转并翻转'?
- 5. C#旋转(转换)问题
- 6. c#图像旋转
- 7. C#旋转矩阵
- 8. c#旋转问题
- 9. C#GDI旋转弹
- 10. 旋转矩形 - C#
- 11. C/C++旋转BMP图像
- 12. 如何使旋转在不同的时间旋转并旋转X?
- 13. 旋转并替换Android的
- 14. 旋转,并与jQuery和CSS
- 15. 用d3旋转并缩放svg javascript
- 16. C#,旋转二维数组
- 17. C二维数组旋转
- 18. 旋转3D模型XAML C#
- 19. C++:BMP旋转图像
- 20. C++旋转线变短
- 21. 旋转图像数学(C#)
- 22. 旋转2D对象C#
- 23. Turbo C++ 3D旋转问题
- 24. 图像旋转C与OpenCV
- 25. C#图表旋转标签
- 26. C++/OpenGL - 旋转矩形
- 27. 在C中旋转多列#
- 28. AVL树,C,旋转实现
- 29. C中的旋转算法?
- 30. 强制旋转目标-c
到目前为止您尝试了什么? – Rik
对不起,但这太宽了:_Detect Largest Contour_ then _Image Transformation_;) –
您应该先发布[MCVE] –