재미있는 이미지 편집 응용 프로그램을 작성했으며 모두 잘되고 있지만 확대/축소 기능에 문제가 있습니다. 이미지 편집기 평면은 512 x 512 픽셀이지만 편집하려는 이미지는 16 x 16뿐입니다. 마우스 좌표를 작은 이미지로 투영하여 픽셀 단위로 편집하는 방법을 알고 싶습니다.더 큰 하나에 작은 격자를 투영하십시오.
나는이 알고리즘을 고안했습니다. 작은 해상도가 16 × 16이고 제가 발견으로
/**
*
* @param pointx The x position of the point thats being bound
* @param pointy The y position of the point thats being bound
* @param oldsizeX The old grid size x of which the point is currently in. (eg ==> 512*512)
* @param oldsizeY The old grid size y of which the point is currently in. (eg 512* ==> 512)
* @param newsizeX The new grid size x for the new grid size of the point. (eg ==> 16*16)
* @param newsizeY The new grid size y for the new grid size of the point. (eg 16* ==> 16)
* @param normalOffsetX The offset x, if any, the grid has in the normal plane (eg ==> 32*32 @ (512*512))
* @param normalOffsetY The offset y, if any, the grid has in the normal plane (eg 32* ==> 32 @ (512*512)
* @return A Vector2 containing the bound points in the new plane.
*/
public static Vector2 bindPoint(int pointx, int pointy, int oldsizeX, int oldsizeY, int newsizeX, int newsizeY,int normalOffsetX,int normalOffsetY) {
Vector2 vec = new Vector2();
int tileSizeX = oldsizeX/newsizeX;
int tileSizeY = oldsizeY/newsizeY;
int offsetX = normalOffsetX, offsetY = normalOffsetY;
vec.x = (int) (pointx/2)/(oldsizeX/tileSizeX) - (offsetX/tileSizeX);
vec.y = (int) (pointy/2)/(oldsizeY/tileSizeY) - (offsetY/tileSizeY);
if(pointx >= normalOffsetX && pointx <= normalOffsetX + oldsizeX && pointy >= normalOffsetY && pointy <= normalOffsetY + oldsizeY) {
return vec;
}else {
return new Vector2(-1,-1);
}
}
이것은 오랫동안 작동하는 전 0.5로 pointX 뾰족한 분할 및 32 × 32 일의 화상 후 2 바뀌면. 내가 알고 싶은 것은 그렇게하는 더 좋은 방법이 있다면, 어떤 줌 레벨에서 어떤 크기의 이미지라도 사용할 수 있다는 것입니다.
나는 늦었고 피곤해서 펜과 종이를 알아 냈습니다. –