C++ 齐玛格垂直翻转

C++ 齐玛格垂直翻转,c++,qt,loops,qimage,C++,Qt,Loops,Qimage,大家好,我有一个map_服务器,它读取PGM文件,然后在QImage上打印它的翻转图像。 这是我的代码。 int width = msg->info.width; int height = msg->info.height; const std::vector<int8_t>& data (msg->data); unsigned char *p, *q; if( mapImage == NULL ) { lineImage

大家好,我有一个map_服务器,它读取PGM文件,然后在QImage上打印它的翻转图像。 这是我的代码。

  int width = msg->info.width;
  int height = msg->info.height;
  const std::vector<int8_t>& data (msg->data);
  unsigned char *p, *q;

  if( mapImage == NULL ) {
      lineImage = new unsigned char[ width * 3 ];
      mapImage = new QImage( width, height, QImage::Format_RGB888 );
  }

  if( mapImage != NULL ) {
      for( int i = 0; i < height; i++ ) {
          q = lineImage;
          p = ( unsigned char * )&data[ i * width ];
          for( int j = 0; j < width; j++ ) {
             *q++ = *p;
             *q++ = *p;
             *q++ = *p;
             p++;
          }
          memcpy( mapImage->scanLine( i ), lineImage, width * 3 );
      }
   }

printf( "Map received!\n" );
int-width=msg->info.width;
int height=msg->info.height;
const std::向量和数据(消息->数据);
无符号字符*p,*q;
如果(mapImage==NULL){
lineImage=新的无符号字符[宽度*3];
mapImage=新QImage(宽度、高度、QImage::格式_RGB888);
}
如果(mapImage!=NULL){
对于(int i=0;iscanLine(i),lineImage,宽度*3);
}
}
printf(“收到地图!\n”);
高度的“for loop”从“0”到极限(高度),我可以假设它读取的图片在极限,直到“0”。

  int width = msg->info.width;
  int height = msg->info.height;
  const std::vector<int8_t>& data (msg->data);
  unsigned char *p, *q;

  if( mapImage == NULL ) {
      lineImage = new unsigned char[ width * 3 ];
      mapImage = new QImage( width, height, QImage::Format_RGB888 );
  }

  if( mapImage != NULL ) {
      for( int i = 0; i < height; i++ ) {
          q = lineImage;
          p = ( unsigned char * )&data[ i * width ];
          for( int j = 0; j < width; j++ ) {
             *q++ = *p;
             *q++ = *p;
             *q++ = *p;
             p++;
          }
          memcpy( mapImage->scanLine( i ), lineImage, width * 3 );
      }
   }

printf( "Map received!\n" );
由于声誉问题,我无法提供图片。但我仍然希望我能在这方面得到一些帮助

谢谢


JeremyEthanKoh.

在JPG和BMP之间转换时,扫描线以Y反转。这是特定于BMP格式的。您的QImage似乎是一个RGB 24 bil位图,您可以直接逐行写入其像素贴图。只需反转Y轴上的扫描线:

if( mapImage != NULL ) {
  for( int i = 0; i < height; i++ ) {
      q = lineImage;
      p = ( unsigned char * )&data[ i * width ];
      for( int j = 0; j < width; j++ ) {
         *q++ = *p;
         *q++ = *p;
         *q++ = *p;
         p++;
      }
      memcpy( mapImage->scanLine( height-i-1 ), lineImage, width * 3 );
  }
}
if(mapImage!=NULL){
对于(int i=0;iscanLine(高度-i-1),lineImage,宽度*3);
}
}

我承认这里有猜测,但如果在一幅图像中使用屏幕坐标系,则只会导致它。@user2672165你是什么意思?但无论如何,这是一件独立的事情,不是吗。。?然后它逐像素读取,逐像素打印出来,唯一的问题是开始的第一个像素不同。啊,老兄,我自己都不知道。看看这个天哪,哇。谢谢你,伙计!你救了我的命。但是你能帮我解释一下为什么是(身高-i-1)?:)@Baj英里