1/* 2 * Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * 计算,当固定容器宽高,选择Contain模式后,图片的实际宽高 18 * @param componentW 容器宽 19 * @param componentH 20 * @param imageW 图片宽 21 * @param imageH 22 * @returns 23 */ 24export function getContainSize(componentW: number, componentH: number, imageW: number, imageH: number): Size { 25 const size: Size = new Size(); 26 // 如果组件宽高比更小,那么宽度会最大 27 const isWidthMax: boolean = componentW / componentH - imageW / imageH <= 0; 28 if (isWidthMax) { 29 size.width = componentW; 30 size.height = componentW / imageW * imageH; 31 } else { 32 size.height = componentH; 33 size.width = componentH / imageH * imageW; 34 } 35 size.scale = size.width / imageW; 36 return size; 37} 38 39export class Size { 40 width: number = 0; 41 height: number = 0; 42 // 缩放比 43 scale: number = 0; 44} 45