Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Bitmap Rotation

Hi everyone?
I m the new user of this forum?
I am a new programmer and working for win32 c.
I have a problem in bitmap rotation.
I loaded the image through BitmapInfoheader and so i want to rotate it.
I tried it but it is not working?
Can anyone help me?

Comments

  • LundinLundin Posts: 3,711Member
    Not sure how helpful this is, but here is some code I wrote once. I used the code to transform a Windows bitmap to binary code loaded into an embedded LCD.

    I believe it transforms the (weird) bitmap format to a more logical format for computer usage, with origo in the upper left corner of the picture. This is quite similar to rotation, since bitmaps are stored "upside-down" in memory.

    [code]BOOL saveFile(const char* filename, const BITMAPFILEHEADER* pBmpFileHeader, FileType type)
    {
    FILE* fp;
    BYTE output[1024];
    BYTE tmp[1024];
    int row,col;
    int size = pBmpFileHeader->bfOffBits + 1024;
    int destCount;
    unsigned char sourceMask;
    unsigned char destMask;

    fp = fopen(filename,"w");

    if(fp == NULL)
    return FALSE;

    for(row=0; row<64; row++)
    memcpy(tmp+row*16u, & ((BYTE*)pBmpFileHeader)[size-(row+1)*16u], 16);

    memset(output,0,1024);

    destCount=0;
    for(col=0; col<16; col++)
    {
    for(sourceMask=0x80; sourceMask!=0; sourceMask>>=1)
    {
    destMask=0x01;
    for(row=0; row<64; row++)
    {
    if((~tmp[row*16u+col]) & sourceMask)
    output[destCount] |= destMask;
    destMask<<=1;
    if(destMask==0x00)
    {
    destMask=0x01;
    destCount++;
    }
    }
    }
    }

    switch(type)
    {
    case C_SOURCE:
    _printCFile(fp,output);
    break;

    case S_RECORD:
    _printSRecord(fp,output);
    break;
    }

    fclose(fp);
    return TRUE;
    }[/code]
  • Malcolm_McLeanMalcolm_McLean Posts: 241Member
    : Hi everyone?
    : I m the new user of this forum?
    : I am a new programmer and working for win32 c.
    : I have a problem in bitmap rotation.
    : I loaded the image through BitmapInfoheader and so i want to rotate
    : it.
    : I tried it but it is not working?
    : Can anyone help me?
    :

    To rotate

    newx = x cos theta - y sin theta
    newy = x sin theta + y cos theta

    work from the destination to the source (so you rotate by -theta). Just use DrawPixel to draw the pixels to the screen. Remember you probably want to rotate by the centre not the origin. So subtract by cx, cy, rotate, add cx, cy again.

  • LundinLundin Posts: 3,711Member
    Except... bitmaps are stored up-side down, and in 32-bit little endian. Meaning they are quite far from a mathematically correct matrix.
  • anujkawasthianujkawasthi Posts: 14Member
    : Except... bitmaps are stored up-side down, and in 32-bit little
    : endian. Meaning they are quite far from a mathematically correct
    : matrix.

    Hi
    I want ro rotate bitmap witout using any library functio.
    So How?
  • Malcolm_McLeanMalcolm_McLean Posts: 241Member
    : : Except... bitmaps are stored up-side down, and in 32-bit little
    : : endian. Meaning they are quite far from a mathematically correct
    : : matrix.
    :
    : Hi
    : I want ro rotate bitmap witout using any library functio.
    : So How?
    :
    Go to my website at

    [link=http://www.personal.leeds.ac.uk/~bgy1mm] here [/link]. Follow the link to "Basic Algorithms" and "sample code". You'll find a bitmap loading routine there. Just take it. It's completely platform-independent. Then rotate the bitmap using the algorithm I gave you - you'll have to manaully calculate the offsets using offset = y * width + x - and save out a bitmap rotated by your theta. You'll have to decide how to handle the corners where the new bitmap is empty.


Sign In or Register to comment.