Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » Image: Rescale proportional propose:  
	
		
		
			| Image: Rescale proportional propose: [message #26946] | 
			Fri, 11 June 2010 16:44   | 
		 
		
			| 
				
	 | 
 
	
		Hello All, 
 
 
I propose to add 2 function in ImageScale (draw package) file: 
Image RescaleProportional(Image &p_image, Size &p_rsz){
	if(!p_image)
		return Image();
	
	Size v_isz = p_image.GetSize();
	Size v_fsz = p_rsz;
	bool v_resize = false;
	
	v_fsz.cy = v_isz.cy * p_rsz.cx / v_isz.cx; // rescale proportional by x
	v_fsz.cx = v_isz.cx * p_rsz.cy / v_isz.cy; // rescale proportional by y
	
	if((v_isz.cx == p_rsz.cx)&&(v_isz.cy <= p_rsz.cy)||(v_isz.cy == p_rsz.cy)&&(v_isz.cx <= p_rsz.cx)){
		// the image do not need to rescale!
		v_resize = false;
	}else if(v_fsz.cx > p_rsz.cx){ // adjust x, y already rescaled by x
		v_fsz.cx = p_rsz.cx;
		v_resize = true;
	}else if (v_fsz.cy > p_rsz.cy){ // adjust y, x already rescaled by y
		v_resize = true;
		v_fsz.cy = p_rsz.cy;
	}else // check if after rescale the size is same as p_rsz
		v_resize = ((v_fsz.cx == p_rsz.cx)||(v_fsz.cy == p_rsz.cy));
	
	if(v_resize){
		ImageRaster v_isrc(p_image);
		ImageEncoder v_m;
		Rescale(v_m, fsz, v_isrc, isz);
		return v_m;
	}else
		return Image(p_image);
}
Image RescaleProportionalMax(Image &p_image, Size &p_rsz){
	if(!p_image)
		return Image();
	
	Size v_isz = p_image.GetSize();
	
	if((v_isz.cx<=p_rsz.cx)&&(v_isz.cy<=p_rsz.cy)){
		return Image(p_image);
	}
	
	return RescaleProportional(p_image, p_rsz);
}
 
 
Best regards, Ion Lupascu (tojocky)
		
		
		
 |  
	| 
		
	 | 
 
 
 |  
  
 
Goto Forum:
 
 Current Time: Tue Nov 04 04:24:53 CET 2025 
 Total time taken to generate the page: 0.05472 seconds 
 |