private static int[] calculateWidthAndHeight(int width,int height,int[] max){
		int[] result=new int[]{width,height};
		double scaleOrig=(double)width/height;
		double scaleMax=(double)max[0]/max[1];
		if(scaleOrig>scaleMax){
			if(width>max[0]){
				result[0]=max[0];
				result[1]=(int)Math.round(max[1]/scaleOrig);
			}
		}else{
			if(height>max[1]){
				result[0]=(int)Math.round(max[0]*scaleOrig);
				result[1]=max[1];
			}
		}
		return result;
	}