프로그래밍
이미지 화면 출력 비율 계산
unsigned
2015. 9. 25. 11:46
반응형
int originalWidth = image.GetWidth(); int originalHeight = image.GetHeight(); // This code calculates the aspect ratio in which I have to draw the image int16 cntrlwidth = controlPosition.right - controlPosition.left; // controlPosition is the custom Control Rect int16 cntrlheigth = controlPosition.bottom - controlPosition.top; float percentWidth = (float)cntrlwidth / (float)originalWidth; float percentHeight = (float)cntrlheigth / (float)originalHeight; float percent = percentHeight < percentWidth ? percentHeight : percentWidth; int newImageWidth = (int)(originalWidth * percent); int newImageHeight = (int)(originalHeight * percent); Gdiplus::RectF imageContainer; imageContainer.X = controlPosition.left; imageContainer.Y = controlPosition.top; imageContainer.Width = controlPosition.right; imageContainer.Height = controlPosition.bottom; Gdiplus::Graphics gdiGraphics(hDC); Gdiplus::Unit scrUnit = Gdiplus::UnitPixel; gdiGraphics.DrawImage(&image, imageContainer, 0, 0, originalWidth, originalHeight, scrUnit);
반응형