I'm working in some graphics programming in java. At the moment I can scale a picture image what I store in a 1D array. (it store row by row)
My code like where is the new position?
newpoz = (int)(x * scale) + (int)(y * scale) * width;
This gives me a position in the array. But it scaling by the 0,0 coordinate what is in the top left corner. How can I set it to the center if the screen? So to the screen.getWidth()/2;screen.getHeight()/2.
Somebody can help with this? If there is any question I will answer in the comments.
To scale pixel coordinates about some center (a, b)
:
(x', y') = ([x - a] * scale + a, [y - b] * scale + b)
Fetch the original pixel data using pixelArray[y * width + x]
as before, and set the destination pixel similarly with the new coordinates.
EDIT: you may also want to look at bilinear interpolation, because the current raw method may give jagged edges in the final image if used directly.