使用C ++旋转bmp文件? [英] rotating a bmp file using C++ ?
本文介绍了使用C ++旋转bmp文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
fstream flower("flower.bmp", ios::in | ios::out | ios::binary);
int width=686;
int height=800;
flower.seekg(18,ios::beg);
flower.put(height);
flower.seekg(4);
flower.put(width);
flower.close();
}
推荐答案
只是交换宽度和高度不会旋转图像。您还需要逐个像素地旋转位图数据。这需要相当多的缓冲处理和数据挖掘。有关如何操作的示例,请查看此处:
为CBitmap添加快速的用户可扩展图像处理支持 [ ^ ]
Just exchanging width and height will not rotate the image. You also need to rotate the bitmap data pixel by pixel. That requires quite a bit of buffer handling and data shoveling. For an example how to do it, look here:
Add fast user-extensible image processing support to CBitmap[^]
我害怕我的建议想一想可能会冒犯你一点,所以我可能要说明这个想法可能意味着什么。
假设你有一些位数据,它告诉你(忘记格式,这是无关紧要的):
你有
宽度= 3,高度= 2,像素数据123456
这意味着第一行是123,第二行是456:
I was afraid that my suggestion to "think a bit" could possibly offend you a bit, so I probably have to illustrate what this thinking could mean.
Suppose you have some bit data, which tells you (forget the "format", it is irrelevant):
you have
width = 3, height = 2, and pixels data 123456
It means that first line is 123 and the second line is 456:
123
456
如果换宽和高度,你会有
If you swap width and height, you would have
width = 2, height = 3:
12
34
56
但顺时针旋转原始图片90°(您可以将计算机屏幕顺时针旋转90°并查看相同的数字),您会看到什么?显然,
But turn original picture 90° clockwise (you can just turn your computer screen 90° clockwise and look at the same numbers), what will you see? apparently,
41
52
63
和counterclickwise:
and counterclickwise:
36
25
14
最后两张图片是正确的,前一张图片是正确的是腐败的。这里有什么不明显的?
这就是nv3的意思,告诉你逐个像素地旋转位图数据。
我希望现在问题应该清楚了。
这篇关于使用C ++旋转bmp文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文