fix(scanQRcode): 修正扫码页面裁切缩放逻辑
调整了中心裁切区域的计算参数和缩放系数,保证画面不变形同时优化裁切逻辑注释
This commit is contained in:
parent
15c502c959
commit
00baf6574a
@ -277,15 +277,16 @@ namespace Kill.UI.Pages
|
||||
// 预览框横向 1080x680
|
||||
// 从旋转后的 1080x1920 中截取中间区域并放大
|
||||
|
||||
// 计算中心裁切区域大小(基于 centerCropRatio)
|
||||
int sourceCropH = Mathf.Max(1, Mathf.RoundToInt(camW * centerCropRatio));
|
||||
int sourceCropW = Mathf.Max(1, Mathf.RoundToInt(camH * centerCropRatio));
|
||||
// 计算中心裁切区域大小
|
||||
// centerCropRatio=1.0 时等于原始裁切(取 targetH 列 / 所有行),无缩放
|
||||
// centerCropRatio<1.0 时取更小区域放大,值越小放大倍数越大
|
||||
int sourceCropH = Mathf.Max(1, Mathf.RoundToInt(targetH * centerCropRatio));
|
||||
int sourceCropW = Mathf.Max(1, Mathf.RoundToInt(targetW * centerCropRatio));
|
||||
int cropY = (camW - sourceCropH) / 2;
|
||||
int cropX = (camH - sourceCropW) / 2;
|
||||
|
||||
// 计算缩放比例
|
||||
float scaleY = (float)sourceCropH / targetH;
|
||||
float scaleX = (float)sourceCropW / targetW;
|
||||
// 两个方向缩放一致,保证不变形
|
||||
float scale = centerCropRatio;
|
||||
|
||||
// 获取相机像素数据
|
||||
Color32[] cameraPixels = webCamTexture.GetPixels32();
|
||||
@ -293,14 +294,14 @@ namespace Kill.UI.Pages
|
||||
|
||||
// 顺时针旋转90度 + 中心裁切 + 缩放
|
||||
// 目标像素 (x, y) 对应源坐标:
|
||||
// srcX = cropY + (targetH-1-y) * scaleY (裁切区域内纵向缩放)
|
||||
// srcY = cropX + x * scaleX (裁切区域内横向缩放)
|
||||
// srcX = cropY + (targetH-1-y) * scale (裁切区域内纵向缩放)
|
||||
// srcY = cropX + x * scale (裁切区域内横向缩放)
|
||||
for (int y = 0; y < targetH; y++)
|
||||
{
|
||||
for (int x = 0; x < targetW; x++)
|
||||
{
|
||||
float srcX = cropY + (targetH - 1 - y) * scaleY;
|
||||
float srcY = cropX + x * scaleX;
|
||||
float srcX = cropY + (targetH - 1 - y) * scale;
|
||||
float srcY = cropX + x * scale;
|
||||
|
||||
// 双线性插值采样
|
||||
int sx = (int)srcX;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user