I’m trying to rotate a bitmap image clockwise 90 degree.
I’ve tried changing the width to height and height to width for the infoheader so when it loops it will loop the height, then width but it doesn’t rotate, so i guess i need to put them into X and Y coordinate from the Byte Array Section. I’ve been stucked for 3 days already, so if possible, please help me! Thank you so much. Please direct me through the codes here, thank you again!
hfile = CreateFile(ofn.lpstrFile, GENERIC_READ, FILE_SHARE_READ, (LPSECURITY_ATTRIBUTES)NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL );
ReadFile(hfile, &bfh, sizeof(bfh), &written, NULL);
ReadFile(hfile, &bih, sizeof(bih), &written, NULL);
bmi.bmiHeader = bih;
int imagesize = bih.biHeight * bih.biWidth * 3; // Allocate necessary data for image
image = new BYTE[imagesize];
image1 = new BYTE[imagesize];
ReadFile(hfile, image, imagesize, &written, NULL);
SetDIBitsToDevice(hdc, 0, 0, bih.biWidth, bih.biHeight, 0, 0, 0,
bih.biHeight, image,&bmi,DIB_RGB_COLORS);
width = bih.biHeight;
height = bih.biWidth;
for(int x=0; x<height; x++)
{
for(int y=0; y<width; y++)
{
image1[(y*height+x)*3+0] = image[(y*height-1-x)*3+0];
image1[(y*height+x)*3+1] = image[(y*height-1-x)*3+1];
image1[(y*height+x)*3+2] = image[(y*height-1-x)*3+2];
}
}
SetDIBitsToDevice(hdc,height,0,width,height,0,0,0,bih.biHeight,image1,&bmi,DIB_RGB_COLORS);
width = bih.biHeight;
height = bih.biWidth;
ReleaseDC(hwnd, hdc);
return 0;
EndPaint(hWnd, &ps);
return 0;
If we can break this down into a class that has a buffer of data and is able to “obtain” and “set” a colour at a matrix index (x,y) from such a matrix then your work will be easier.
Thus we could have in the simplest
and
Of course we could put the RGB into a single “struct”.
Then you could have
in your loop and that should rotate as long as your class is set up correctly.