본문 바로가기

프로그래밍

이미지 화면 출력 비율 계산

반응형
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);

 

반응형

'프로그래밍' 카테고리의 다른 글

TCP 유령세션  (0) 2020.06.25
Sqlite Insert 속도 문제시  (0) 2016.07.19