How to rotate image "safely"

I got AHK script which uses GDI or GDI+ and there is rotation funtion, which rotates image (map which has several solid colors like green,blue,red,yellow,orange,white,gray,"desert"). I would like to do such rotation which will not blur the image but will use the colors which I use and need to be used so it is not blured. So the rotation function should find the closest color - one of the set.

Yet it has no sense to paste here all the code which is in AHK because there is gdip library which does the things. But this is what the AHK does:

1
2
3
4
5
6
pBitmap := Gdip_CreateBitmap(RWidth, RHeight)                       ; Create a new bitmap
G := Gdip_GraphicsFromImage(pBitmap)                                ; Get a pointer to the graphics of the bitmap
Gdip_SetSmoothingMode(G, 4)
Gdip_SetInterpolationMode(G, 7)
Gdip_TranslateWorldTransform(G, xTranslation, yTranslation)
Gdip_RotateWorldTransform(G, Angle)


And the Gdip_RotateWorldTransform does this dll call:
DllCall("gdiplus\GdipRotateWorldTransform", "uint", pGraphics, "float", Angle, "int", MatrixOrder)

I don't know id I need all these functions, but need to find a way how to skip bluring of the image.

Here - on right: original window, from where the image is taken and rotated
the resulted images is displayed under the window so you see the blured dots.
http://oi61.tinypic.com/2ztepty.jpg

I am interested what function to use or how to use them in C++ and I would try to add them to AHK.

Edit:
I have tried Gdip_SetInterpolationMode(G, 5)
which gives no blured points. This looks like very close solution what I thought it could be. But one more idea:
Is it possible to improve results, with this method?
1) First create image A from original image which will be blured.
e.g. Interpolation Mode 7 and rotate it
2) Then create next image B from the original with interpolation mode 5 and rotate it
3) Create new image which will compare the pixel with image A and B. And find the best color. E.g. In the image B there are blue dots beside the blue line which I want to remove. If it will compare with image A, program will see that there is not full blue, and there for will use the color nearest to the blured green -> so it will create clear green pixel.

What I am trying to explain that when you compare two images, the program could decide if the pixel from B should be placed there or not. But of not, so it must find nearest color which is not nearest of blue.
Last edited on
I would guess that it is your interpolation mode. You would probably have to look in the docs for what modes are available to you and use the one you want most.

Interpolation has to do with the way the pixels are colored on a scale/rotate. Consider an image that is all white except for a 1px black horizontal line. If you rotate that image 1 degree, what should the image look like?

Some interpolation modes will try to blend pixel colors to make the slanted line as natural as possible. Other modes will maintain the same color scheme but it may look jagged.

My first attempt would be to try no interpolation.
Last edited on
When you edit your post It does not show up as a reply, fortunate I did a page refresh.

Try no interpolation.
LowestOne, I have tried it without interp. but it looks the same like with it.

So did you read my update, about the idea of comparing two images? The key would be to recognise the pixel which has not blue tone in it. But hard to define such function, huh? What I like on the idea is that I already have one image which is almost good, but has some bad pixels which should be removed... and replaced with green. But this is individual task because the pixel can be any color. I must yet check color is sea terrain.

Yeah, here are more colors (I think here are the most colors which are possible in the map):
http://oi60.tinypic.com/vfilb4.jpg
Last edited on
Topic archived. No new replies allowed.