지정된 경계에 맞게 이미지의 크기를 줄이는 함수를 작성하고 싶습니다. 예를 들어, 1280x800에 맞도록 2000x2333 이미지의 크기를 조정하려고합니다. 종횡비는 유지되어야합니다. 나는 다음 알고리즘을 제안했다 :이미지 크기 조정 알고리즘
NSSize mysize = [self pixelSize]; // just to get the size of the original image
int neww, newh = 0;
float thumbratio = width/height; // width and height are maximum thumbnail's bounds
float imgratio = mysize.width/mysize.height;
if (imgratio > thumbratio)
{
float scale = mysize.width/width;
newh = round(mysize.height/scale);
neww = width;
}
else
{
float scale = mysize.height/height;
neww = round(mysize.width/scale);
newh = height;
}
그리고 그것은 보였다. 글쎄 ... 하지만 1280x800 크기의 이미지를 1280x800 크기로 조정하려고 시도한 결과 1280x1024 (1280x800에 맞지 않음)라는 결과가 나왔습니다.
누구나이 알고리즘이 어떻게 작동해야하는지 아이디어가 있습니까?
아 난 후, 비율이 1, 1.28 것 화면 1280x800에 1280X1024의 귀하의 예제 캐스트에 대한 추가해야는 1000 X 800 – GWW
감사합니다 것입니다 크기를 조정! 나는 마침내 그것이 일하는 것이라고 생각한다! – Marius