c++builer图像旋转问题

家有2亩地 2012-09-05 03:09:36
pBitmap2->Height = pBitmap1->Width;
pBitmap2->Width = pBitmap1->Height;

for(int y = 0; y<pBitmap1->Width; y++)
{
ptr2 = (Byte*)(pBitmap2->ScanLine[y]);
for(int x=0; x<pBitmap1->Height; x++)
{
ptr1 = (Byte*)(pBitmap1->ScanLine[x]);
ptr2[x] = ptr1[y];
}
}
旋转90度,我不明白的是如何把pBitmap1->ScanLine()值传递给pBitmap2->ScanLine(),有人懂吗 帮我解答下
ps:ptr1与ptr2是两个字节型指针
...全文
142 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
家有2亩地 2012-09-13
  • 打赏
  • 举报
回复
谢谢解答,我还是有点迷糊,你看下我注释对不对
pBitmap2->Height = pBitmap1->Width;
pBitmap2->Width = pBitmap1->Height;

for(int y = 0; y<pBitmap1->Width; y++)
{
ptr2 = (Byte*)(pBitmap2->ScanLine[y]);//把ScanLine[1]的像素传给递给ptr2
for(int x=0; x<pBitmap1->Height; x++)
{
ptr1 = (Byte*)(pBitmap1->ScanLine[x]);//把pBitmap1->ScanLine[1]的值传递给ptr1
ptr2[x] = ptr1[y]; //在把ptr1的值传递给ptr2
}
}
上边的程序就是把pBitmap1的行像素,通过循环把ptr1传给ptr2的列,
ptr2的值如何处理的啊 我就是这点不明白,ptr2怎么到了pBitmap2->ScanLine[]中的






[Quote=引用 7 楼 的回复:]

我的意思是颠倒的顺序不是赋给了ptr2了吗,然后ptr2中的值就保留了还是传递给不大参数啦
-------------------------------------------
有点没弄懂这句话的意思

你可以想象一下如何把一个M×N的数组旋转成N×M的数组
位图本质上就是一个二维数组,scanline用来访问数组中的某一行
[/Quote]
家有2亩地 2012-09-13
  • 打赏
  • 举报
回复
明白了 是我指针那个地方没学好
十分感谢您的细心解答 哈哈 谢谢啦
[Quote=引用 9 楼 的回复:]

重新注释了一下,看看是否更好理解一些,这是一个图像的转置,还不是旋转
C/C++ code

for(int y = 0; y<pBitmap1->Width; y++) { // 从左到右扫描bitmap1的每一列

ptr2 = (Byte*)(pBitmap2->ScanLine[y]);// ptr2指向了bitmap2的第y行

for……
[/Quote]
dataxdata 2012-09-13
  • 打赏
  • 举报
回复
重新注释了一下,看看是否更好理解一些,这是一个图像的转置,还不是旋转

for(int y = 0; y<pBitmap1->Width; y++) { // 从左到右扫描bitmap1的每一列

ptr2 = (Byte*)(pBitmap2->ScanLine[y]);// ptr2指向了bitmap2的第y行

for(int x=0; x<pBitmap1->Height; x++) { // 对于bitmap1中的每一列,按行扫描
ptr1 = (Byte*)(pBitmap1->ScanLine[x]);// ptr1指向bitmap1中的第x行
ptr2[x] = ptr1[y]; // 把bitmap1中第x行第y列的值传递给bitmap2中的第y行第x列
}
}

重新写一下这个转置,应该看得更清楚一些

for ( int i=0; i<pBitmap2->Height; i++ )
for ( int j=0; j<pBitmap2->Width; j++ )
pBitmap2->ScanLine[i][j] = pBitmap1->ScanLine[j][i];

如果使用了中间变量ptr2,就是

for ( int i=0; i<pBitmap2->Height; i++ ) {
byte *ptr2 = (Byte*)pBitmap2->ScanLine[i];
for ( int j=0; j<pBitmap2->Width; j++ )
ptr2[j] = pBitmap1->ScanLine[j][i];
}

如果再加上中间变量ptr1,就变得和最原始的代码差不多了

for ( int i=0; i<pBitmap2->Height; i++ ) {
byte *ptr2 = (Byte*)pBitmap2->ScanLine[i];
for ( int j=0; j<pBitmap2->Width; j++ ) {
byte *ptr1 = (Byte*)pBitmap1->ScanLine[j];
ptr2[j] = ptr1[i];
}
}
dataxdata 2012-09-12
  • 打赏
  • 举报
回复
我的意思是颠倒的顺序不是赋给了ptr2了吗,然后ptr2中的值就保留了还是传递给不大参数啦
-------------------------------------------
有点没弄懂这句话的意思

你可以想象一下如何把一个M×N的数组旋转成N×M的数组
位图本质上就是一个二维数组,scanline用来访问数组中的某一行
家有2亩地 2012-09-12
  • 打赏
  • 举报
回复
我的意思是颠倒的顺序不是赋给了ptr2了吗,然后ptr2中的值就保留了还是传递给不大参数啦

你贴的就是旋转程序啊,左右90度旋转就是一个矩阵转置,行变列,列变行,180度旋转就是把行和列都颠倒过来,左右和上下翻转就是单独颠倒列和行,无外乎这几种变化及其组合
[/Quote]
dataxdata 2012-09-06
  • 打赏
  • 举报
回复
你贴的就是旋转程序啊,左右90度旋转就是一个矩阵转置,行变列,列变行,180度旋转就是把行和列都颠倒过来,左右和上下翻转就是单独颠倒列和行,无外乎这几种变化及其组合
家有2亩地 2012-09-06
  • 打赏
  • 举报
回复
这个我知道啊,但是我不清楚他怎么旋转的 你编过旋转的程序吗
[Quote=引用 3 楼 的回复:]

scanline指向的就是某一行的像素值啊
[/Quote]
dataxdata 2012-09-05
  • 打赏
  • 举报
回复
scanline指向的就是某一行的像素值啊
家有2亩地 2012-09-05
  • 打赏
  • 举报
回复
那第二个图像时如何获得第一个图像值的啊
哇 是你啊[Quote=引用 1 楼 的回复:]

就是旋转像素点,scanline是描述像素行的指针,两个图像间的scanline没有直接关系
[/Quote]
dataxdata 2012-09-05
  • 打赏
  • 举报
回复
就是旋转像素点,scanline是描述像素行的指针,两个图像间的scanline没有直接关系

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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