拼接图片可以参考:https://developer.huawei.com/consumer/cn/forum/topic/0209140872409552061?fid=0102683795438680754图片裁剪可以参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-faqs-V5/faqs-image-7-V5// Crop 4:3 ... class RegionItem { /** * width coordinate. */ x: number; /** * height coordinate. */ y: number; constructor(x: number, y: number) { this.x = x; this.y = y; } } export async function cropCommon(pixelMap: PixelMap, cropWidth: number, cropHeight: number, cropPosition: RegionItem) { pixelMap.crop({ size: { width: cropWidth, height: cropHeight }, x: cropPosition.x, y: cropPosition.y }); } // 传入image.PixelMap、图片width、图片height三个参数,获取到裁剪后的图片宽度和高度后将参数传入cropCommon方法 export async function banner(pixelMap: PixelMap, width: number, height: number) { if (width <= height) { const cropWidth = width; const cropHeight = Math.floor(width * 0.75); const cropPosition = new RegionItem(0, Math.floor((height - cropHeight) / 2)); cropCommon(pixelMap, cropWidth, cropHeight, cropPosition); return; } if (width * 0.75 >= height) { const cropWidth = Math.floor(height / 0.75); const cropHeight = height; const cropPosition = new RegionItem(Math.floor((width - cropWidth) / 2), 0); cropCommon(pixelMap, cropWidth, cropHeight, cropPosition); return; } const cropWidth = width; const cropHeight = Math.floor(width * 0.75); const cropPosition = new RegionItem(0, Math.floor((height - cropHeight) / 2)); cropCommon(pixelMap, cropWidth, cropHeight, cropPosition); }
拼接图片可以参考:https://developer.huawei.com/consumer/cn/forum/topic/0209140872409552061?fid=0102683795438680754
图片裁剪可以参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-faqs-V5/faqs-image-7-V5