### Author Topic: Calculate the new image size  (Read 1376 times)

#### Grincheux

• Guest
##### Calculate the new image size
« on: March 23, 2016, 09:02:03 am »
A function to recalculate the size of an image image.
Quote
Parameters :

__dwOriginalWidth : The width of the original image
__dwOriginalHeight : The height of the original image
__dwExpectedWidth : The expexted with
__dwExpectedHeight : The expected height
__lpdwNewWidth : Pointer for storing the new width
__lpdwNewHeight : Pointer for storing the new height
The function computes the ratio of the image.
If the temporary width (or height) is greather then the expected value, the function recomputes the values  for they
are equal to one of the expected values.

Code: [Select]
`void ImageResize(DWORD __dwOriginalWidth,DWORD __dwOriginalHeight,DWORD __dwExpectedWidth,DWORD __dwExpectedHeight,DWORD *__lpdwNewWidth,DWORD *__lpdwNewHeight){ double dRatio ; DWORD _dwWidth, _dwHeight ; if(__dwOriginalWidth > __dwOriginalHeight) { dRatio = (double) __dwOriginalHeight / (double) __dwOriginalWidth ; _dwWidth = __dwExpectedWidth ; _dwHeight = (DWORD) ((double) _dwWidth * dRatio) ; if(_dwHeight > __dwExpectedHeight) { _dwHeight = __dwExpectedHeight ; _dwWidth = (DWORD) (((double) _dwHeight) / dRatio) ; } *__lpdwNewWidth = _dwWidth ; *__lpdwNewHeight = _dwHeight ; return ; } dRatio = (double) __dwOriginalWidth / (double) __dwOriginalHeight ; _dwHeight = __dwExpectedHeight ; _dwWidth = (DWORD) (((double) _dwHeight) * dRatio) ; if(_dwWidth > __dwExpectedWidth) { _dwWidth = __dwExpectedWidth ; _dwHeight = (DWORD) (((double) _dwWidth) / dRatio) ; } *__lpdwNewWidth = _dwWidth ; *__lpdwNewHeight = _dwHeight ; return ;}`