perf(scanQRcode): 优化二维码扫描的像素数据获取方式

1.  减少了扫描间隔从0.2秒到0.1秒,提升扫描灵敏度
2.  直接获取纹理原始RGB字节数据,移除手动转换像素的循环,减少性能开销
This commit is contained in:
“虞渠成” 2026-07-23 16:26:37 +08:00
parent 1e1fd209f9
commit 6626c8d613

View File

@ -22,7 +22,7 @@ namespace Kill.UI.Pages
[Header("UI组件")]
public RawImage cameraPreview; // 摄像头预览
[Header("扫描设置")]
float scanInterval = 0.2f; // 扫描间隔(秒)
float scanInterval = 0.1f; // 扫描间隔(秒)
public ScanType scanType = ScanType.ConnectDevice; // 扫描类型
[Header("小二维码优化")]
@ -382,17 +382,10 @@ namespace Kill.UI.Pages
// 异步解析二维码以避免卡顿
if (useAsyncScan)
{
// 在主线程提取像素数据Unity API 必须在主线程调用)
Color32[] pixels = previewTexture.GetPixels32();
// 直接获取 RGB24 原始字节,无需手动转换
byte[] rgbBytes = previewTexture.GetRawTextureData<byte>();
int texWidth = previewTexture.width;
int texHeight = previewTexture.height;
byte[] rgbBytes = new byte[pixels.Length * 3];
for (int i = 0; i < pixels.Length; i++)
{
rgbBytes[i * 3] = pixels[i].r;
rgbBytes[i * 3 + 1] = pixels[i].g;
rgbBytes[i * 3 + 2] = pixels[i].b;
}
string result = null;
bool scanComplete = false;