Does anyone know how i would go about rotating an image 90 degrees clockwise and anticlockwise as i am finding it hard to find information on it
i am using borland c++ builder
Thanks
This is a discussion on Rotation within the Windows Programming forums, part of the Platform Specific Boards category; Does anyone know how i would go about rotating an image 90 degrees clockwise and anticlockwise as i am finding ...
Does anyone know how i would go about rotating an image 90 degrees clockwise and anticlockwise as i am finding it hard to find information on it
i am using borland c++ builder
Thanks
trigonometry
lets say you have a pixel at x , y. where (0, 0) is top left. (w, h) is width height. (a,b) = (x-w/2, h/2 - y)
where m is the length from (0, 0) defined at center of image to pixel
x' = mcos(k+90) = -sin(k)m = -b
y' = msin(k+90) = mcos(k) = a
apply transformation
x'' = x' + w/2 = w/2 - b = w/2 - [h/2 - y] = w/2 + y - h/2
y'' = h/2 - y' = h/2 - a = h/2 - [x/2 - w/2] = h/2 + w/2 - x/2
your final points x'' and y'' are the new coordinates. For better effect you might want to do a similar thing except assume you have a point go backward to find what pixel should go there. This way it will eliminate "white spots", and look more continious.
Um, or just take the container holding the individual pixels and put them into a new container where the width == height of the original, and height == width of the original.
Say you have a 3 by 4 pixel image (very simple)
So pixel 1 would go in the bottom left pixel slot 2 would be just above that. And so on and so forth. Perhaps if I get bored I will show an example with an array.Code:1 2 3 4 5 6 7 8 9 10 11 12
yeah i think i understand what you mean - i am unsure how i would implement this tho - can you give me a few hints on how to cover come this?
Basically, if you have an pixel with coordinates x,y and you want to get the pixel coordinates after an rotation of alpha degrees, you multiply the coordinates in an 3 dimensional space by the following matrix:
What you have to do is create an destination image with the same dimensions as your original image (or different dimensions if you calculate the bounding box of the 4 corner pixels rotated by that matrix) and then for each pixel of the destination image, you apply the inverted rotation matrix to find the source pixel.
The code would look like this:
1. Calculate the inverse of the rotation matrix:
2. Create an empty image with the same dimensions as your original image
3.
Since it's a 3x3 matrix, you need to transform your 2D coordinations x,y into a 3D coordinate system by fixing the 3rd dimensions z to 1. (x,y) -> (x,y,1).Code:for (i = 0; i < width; i++) { for (j = 0; j < height; j++) { pixel(i,j) = InverseRotation(i,j); } }
But seeing what you did with the last thread I tried to help you, instead of trying to understand how things really work, you try to find a function somewhere that does the job for you.