giorgik
22nd April 2013, 12:05
Hello everyone, I have an image assets / stall.png where asset is a directory located under the root of my program. I would like to copy my image in memory starting from img_flip.
This is the code that I wrote:
QImage img;
img.load(filename);
if (img.isNull())
{
printf( "unable to open image: %s\n", filename );
return 0;
}
QImage gldata = QGLWidget::convertToGLFormat(img);
uchar *pixels = (uint8_t *)gldata.bits();
//vertically flip the image
int img_size = gldata.width() * gldata.height() * gldata.depth();
uint8_t *img_flip = new uint8_t[ img_size ];
const int row_width = gldata.width() * gldata.depth();
for( int i = 0; i < gldata.height(); i++ )
memcpy( img_flip + ( i * row_width ), pixels + ( (gldata.height() - i - 1) * row_width ),
row_width );
I must have made a mistake because the execution stops after copying with i = 7.
Can you help me fix my error ?
This is the code that I wrote:
QImage img;
img.load(filename);
if (img.isNull())
{
printf( "unable to open image: %s\n", filename );
return 0;
}
QImage gldata = QGLWidget::convertToGLFormat(img);
uchar *pixels = (uint8_t *)gldata.bits();
//vertically flip the image
int img_size = gldata.width() * gldata.height() * gldata.depth();
uint8_t *img_flip = new uint8_t[ img_size ];
const int row_width = gldata.width() * gldata.depth();
for( int i = 0; i < gldata.height(); i++ )
memcpy( img_flip + ( i * row_width ), pixels + ( (gldata.height() - i - 1) * row_width ),
row_width );
I must have made a mistake because the execution stops after copying with i = 7.
Can you help me fix my error ?