2017-12-08 13 views
0

큰 이미지를 처리하려고합니다. 처리하는 데 너무 많은 시간이 걸리기 때문에 이전의 이미지 크기를 조절하고 있습니다. 처리 후 사각형을 그립니다. 작은 크기의 이미지.이 사각형의 좌표를 원래의 비 눈금 이미지로 변환 할 수 있습니까? 예 : 비 눈금 이미지의 같은 위치에 사각형을 그립니다.축소 된 크기의 이미지에서 동일한 사각형 위치 가져 오기

나는 이미지

public static Size ResizeKeepAspect(Size CurrentDimensions, int maxWidth, int maxHeight) 
{ 
    int newHeight = CurrentDimensions.Height; 
    int newWidth = CurrentDimensions.Width; 
    if (maxWidth > 0 && newWidth > maxWidth) //WidthResize 
    { 
     Decimal divider = Math.Abs((Decimal)newWidth/(Decimal)maxWidth); 
     newWidth = maxWidth; 
     newHeight = (int)Math.Round((Decimal)(newHeight/divider)); 
    } 
    if (maxHeight > 0 && newHeight > maxHeight) //HeightResize 
    { 
     Decimal divider = Math.Abs((Decimal)newHeight/(Decimal)maxHeight); 
     newHeight = maxHeight; 
     newWidth = (int)Math.Round((Decimal)(newWidth/divider)); 
    } 
    return new Size(newWidth, newHeight); 
} 

enter image description here

enter image description here

답변

1
Rectangle ConvertToLargeRect(Rectangle smallRect, Size largeImageSize, Size smallImageSize) 
{ 
    double xScale = (double)largeImageSize.Width/smallImageSize.Width; 
    double yScale = (double)largeImageSize.Height/smallImageSize.Height;  
    int x = (int)(smallRect.X * xScale + 0.5); 
    int y = (int)(smallRect.Y * yScale + 0.5); 
    int right = (int)(smallRect.Right * xScale + 0.5); 
    int bottom = (int)(smallRect.Bottom * yScale + 0.5); 
    return new Rectangle(x, y, right - x, bottom - y); 
} 
+0

내가 확인하고 다시 당신에게 ... 감사합니다 – techno

0

그것은 단순한 관계 계산의를 달성하기 위해 노력하고 무엇을 임에게 크기를 조정하려면 다음 코드를 사용하고 있습니다. 예를 들어 :

Image A 100 (w) x 100 (h): Pixel x = 10, y = 30 
Image B 200 (w) x 200 (h): Pixel x = a, y = b 

10/100 (w) = a/200 (w) 
200 (w) * 10/100 (w) = a 
a = 20 

30/100 (h) = b/200 (h) 
200 (h) * 30/100 (h) = b 
a = 60 
+0

당신은 일반적인 계산 코드 ... 나는 이미지의 크기를 조정 기존의 일부 코드가 필요 @techno – techno

+0

을 제공하십시오 수 있습니다. 현재 크기 계산 만 표시됩니다. – ViRuSTriNiTy