Read a bitmap into matrix



  • Hello dear programmers,
    Well i have a bitmap i have to do a rotation with mathematical methodes to rotate the image.
    well as i searched ,there is a QBitmap class specially designed for working with bitmap but i couldn't find any special event to convert my QBitmap to QMatrix or int arrays.
    take a look at this example :

    //Open the source and create the destination bitmap 
    Graphics::TBitmap *SrcBitmap=new Graphics::TBitmap; 
    Graphics::TBitmap *DestBitmap=new Graphics::TBitmap; 
    SrcBitmap->LoadFromFile("YourBitmap.bmp");
     
    //rotate by 90° 
    
    DestBitmap->Width=SrcBitmap->Height; 
    DestBitmap->Height=SrcBitmap->Width; 
    
    //Rotate one pixel at a time 
    for (int x=0;x<SrcBitmap->Width;x++) 
    { 
      for(int y=0;y<SrcBitmap->Height;y++) 
      { 
        DestBitmap->Canvas->Pixels[y][SrcBitmap->Width-1-x]= 
           SrcBitmap->Canvas->Pixels[x][y]; 
      } 
    } 
    
    //Assign the Destination bitmap to a TImage 
    Image1->Picture->Bitmap=DestBitmap; 
    delete DestBitmap; 
    delete SrcBitmap;
    

    i want to do something like that in Qt.
    i think im not in the right path ,any idea what to do ?



  • QMatrix is obsolete, you can use QTransform with QPixmap::transformed() to do matrix transformations on the image.

    QPixmap image("YourBitmap.bmp"); //I'm using QPixmap as I'm quite sure you don't want a monochrome bitmap but you can change it
    QTransform transformation;
    transformation.rotate(90.0);
    QPixmap rotadedImage= image.transformed(transformation);
    


  • @VRonin
    well thnQ sir for your help.
    another Question.
    i found the example above in the google ,looks like a C++ code.
    any idea what library it uses ?

    Graphics::TBitmap
    


  • Looks like borland specific library


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.