easyx图片旋转30度
时间: 2024-06-19 21:02:40 浏览: 217
在easyx中,可以通过使用rotateimage函数来旋转图片。该函数需要传入四个参数:旋转后的目标矩形、原图所在矩形、旋转角度、以及是否保持图片大小。具体操作如下:
1.加载图片
```
IMAGE img;
loadimage(&img, _T("图片路径"));
```
2.设置旋转角度
```
float angle = 30.0f;
```
3.设置旋转后的目标矩形
```
int w = img.getwidth();
int h = img.getheight();
int cx = w / 2;
int cy = h / 2;
int r = (int)(sqrt(w * w + h * h) + 0.5f);
int left = cx - r;
int top = cy - r;
int right = cx + r;
int bottom = cy + r;
RECT dstRect = {left, top, right, bottom};
```
4.设置原图所在矩形
```
RECT srcRect = {0, 0, w, h};
```
5.调用rotateimage函数进行旋转
```
rotateimage(&dstRect, &img, angle, true);
```
完整代码如下:
```
#include<graphics.h>
#include<cmath>
int main()
{
initgraph(640, 480);
IMAGE img;
loadimage(&img, _T("图片路径"));
float angle = 30.0f;
int w = img.getwidth();
int h = img.getheight();
int cx = w / 2;
int cy = h / 2;
int r = (int)(sqrt(w * w + h * h) + 0.5f);
int left = cx - r;
int top = cy - r;
int right = cx + r;
int bottom = cy + r;
RECT dstRect = {left, top, right, bottom};
RECT srcRect = {0, 0, w, h};
rotateimage(&dstRect, &img, angle, true);
// 绘制旋转后的图片
putimage(left, top, &img);
// 关闭绘图窗口
closegraph();
return 0;
}
```
阅读全文