tags:

views:

71

answers:

3

Hello Experts,

I am trying to create an avi file for a given jpg images. I am reading jpg's using a library and preparing hbitmap for it. Finally i am adding it to create avi file. But my final avi file contains the inverted images. I kept nagative for hight in bitmapheader. Still my hbitmap is inverted. Can you please help why the error

Here i am giving the code which i implemented

void makeVideo()

{

GoldImage Test ;

for(int i=0;i<10;i++)

{

Test.SetImage(m_MyImage[i])

HBITMAP hBitmap;
Test.GetBitMap(0,0,hBitmap);

if(i==0)

{

avi = CreateAvi("test.avi",1000,NULL);
 AVICOMPRESSOPTIONS opts; ZeroMemory(&opts,sizeof(opts));

SetAviVideoCompression(avi,hBitmap,&opts,true,NULL);

}

AddAviFrame(avi,hBitmap);

}

CloseAvi();

}


void GoldImage::GetBitMap(HBITMAP &hBitmap)

{

BITMAPINFOHEADER bmi;

bmi.biSize = sizeof(BITMAPINFOHEADER);   
        bmi.biWidth = Width   
        **bmi.biHeight = (-1)*Height;**
        bmi.biPlanes = 1;               
        bmi.biBitCount = 32;          
        **bmi.biCompression = BI_RGB;**
        bmi.biSizeImage = 0;           
        bmi.biXPelsPerMeter = 0;       
        bmi.biYPelsPerMeter = 0;       
        bmi.biClrUsed = 0;           
        bmi.biClrImportant = 0;



RGBQUAD *prgbaDIB = 0;
        hBitmap = CreateDIBSection ( NULL, (BITMAPINFO *)&bmi,          DIB_RGB_COLORS,    (void**)&prgbaDIB,   NULL,  0   );



const unsigned int columns = m_Image.columns();
        const unsigned int rows = m_Image.rows();

        RGBQUAD *pDestPixel = prgbaDIB;

        for( unsigned int row = 0 ; row < rows ; row++ )
         {
            const PixelPacket *pPixels = m_Image.getConstPixels(0,row,columns,1);

for( unsigned long nPixelCount = columns; nPixelCount ; nPixelCount-- )
              {
                pDestPixel->rgbRed = ScaleQuantumToChar(pPixels->red);
                pDestPixel->rgbGreen = ScaleQuantumToChar(pPixels->green);
                pDestPixel->rgbBlue = ScaleQuantumToChar(pPixels->blue);
                pDestPixel->rgbReserved = 0;
                ++pDestPixel;
                ++pPixels;
              }

          }

}

Thanks in Advance

+2  A: 

Bitmaps have their scanlines stored up-side down. You'll have to compensate for this when you directly write their pixels.

Hans Passant
A: 

Hello All,

Thanks for your reply.

I am a beginer for bitmaps and accroding my knowledge the bitmaps are up side down. But if we use -height instead of height in BITMAPHEADER then we will get correct image. I used nagative for height. But still i am getting upside down image. We can observe the code above.

Can you please help me if i am wrong.

Thanks in advance

wizards26
A: 

hello all,

i solved my problem. i copied into another hbitmap in reverse. Is is correct or wrong?

wizards26