NO

Author Topic: Resizing an image  (Read 461 times)

Offline HellOfMice

  • Member
  • *
  • Posts: 221
  • Never be pleased, always improve
Resizing an image
« on: December 05, 2024, 08:11:15 PM »
If you want to resize an image it is a good idea to keep the proportions.
This is what the function does

Code: [Select]
double ImageResize(DWORD __dwOriginalWidth,DWORD __dwOriginalHeight,DWORD __dwExpectedWidth,DWORD __dwExpectedHeight,DWORD *__lpdwNewWidth,DWORD *__lpdwNewHeight)
{
   register      DWORD   _dwWidth ;
   register      DWORD   _dwHeight ;

   alignas(double)   double   dRatio ;

   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) ;
   }

   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 (dRatio) ;
}
--------------------------------
Kenavo