Skip to content

Commit 40eabc7

Browse files
committed
recycle image buffer
1 parent 61b0246 commit 40eabc7

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Stratum.Droid/src/QrCode/QrCodeImageAnalyser.cs

+10-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class QrCodeImageAnalyser : Java.Lang.Object, ImageAnalysis.IAnalyzer
2424
TryInvert = true,
2525
Binarizer = Binarizer.GlobalHistogram
2626
});
27+
28+
private byte[] _buffer = [];
2729

2830
public void Analyze(IImageProxy imageProxy)
2931
{
@@ -47,10 +49,15 @@ private void AnalyseInternal(IImageProxy imageProxy)
4749
using var lumPlane = imageProxy.Image.GetPlanes()[0];
4850

4951
lumPlane.Buffer.Rewind();
50-
var bytes = new byte[lumPlane.Buffer.Remaining()];
51-
lumPlane.Buffer.Get(bytes);
52+
53+
if (lumPlane.Buffer.Remaining() != _buffer.Length)
54+
{
55+
_buffer = new byte[lumPlane.Buffer.Remaining()];
56+
}
57+
58+
lumPlane.Buffer.Get(_buffer);
5259

53-
using var imageView = new ImageView(bytes, imageProxy.Width, imageProxy.Height, ImageFormat.Lum, lumPlane.RowStride, lumPlane.PixelStride);
60+
using var imageView = new ImageView(_buffer, imageProxy.Width, imageProxy.Height, ImageFormat.Lum, lumPlane.RowStride, lumPlane.PixelStride);
5461
imageView.Crop(imageProxy.CropRect.Left, imageProxy.CropRect.Top, imageProxy.CropRect.Width(), imageProxy.CropRect.Height());
5562
imageView.Rotate(imageProxy.ImageInfo.RotationDegrees);
5663

0 commit comments

Comments
 (0)