Image PropRescale(const Image& im, const Size res_size); Image PropRescale(const Image& im, const int cx, const int cy); Image PropRescale(const Image& im, const ImageCtrl& imc); void PropRescale(const Image& im, ImageCtrl& imc ,const bool setimage);
Image PropRescale(const Image& im, const Size res_size){ Size imsize,ressize=res_size; imsize = im.GetSize(); if (imsize.cx > 0 && imsize.cy > 0) { double ixy = double(imsize.cx)/imsize.cy; double rxy = double(ressize.cx)/ressize.cy; if (rxy>ixy) { ressize.cx = ressize.cy*imsize.cx/imsize.cy; } else { ressize.cy = ressize.cx*imsize.cy/imsize.cx; } return Rescale(im,ressize); } } Image PropRescale(const Image& im,const int cx,const int cy) { Size ressize; ressize.cx = cx; ressize.cy = cy; return PropRescale(im,ressize); } Image PropRescale(const Image& im, const ImageCtrl& imc) { Image i = PropRescale(im,imc.GetSize()); return i; } void PropRescale(const Image& im, ImageCtrl& imc ,const bool setimage) { Image i = PropRescale(im,imc.GetSize()); if (setimage) imc.SetImage(i); return; }
template <class T> Rect_<T> FitInFrame(const Size_<T> &frame, const Size_<T> &object) { double frameAspect = frame.cx/(double)frame.cy; double objectAspect = object.cx/(double)object.cy; if (frameAspect > objectAspect) { double x = (frame.cx - objectAspect*frame.cy)/2.; return Rect_<T>((T)x, 0, (T)(x + objectAspect*frame.cy), frame.cy); } else { double y = (frame.cy - frame.cx/objectAspect)/2.; return Rect_<T>(0, (T)y, frame.cx, (T)(y + frame.cx/objectAspect)); } }
Quote: |
Could you give an example of use this template? |
void MyImage::Paint(Draw& w) { w.DrawImage(FitInFrame(GetSize(), image->GetSize()), image); }
Quote: |
.... view an image I created one. After that I discover a control for that |
luzr wrote on Thu, 24 December 2009 11:06 |
BTW, since the dawn of U++, there is GetFitSize function and Rect::CenterPos method.... Mirek |