は私が原因とどのように私はそれを防ぐことができますする必要がありますどのようなCameraSource例外java.lang.OutOfMemoryErrorを
byte[] byteArray = new byte[bufferSize];
..次の行..に
Exception java.lang.OutOfMemoryError:
上の問題を抱えています。
CODE
private byte[] createPreviewBuffer(Size previewSize) {
int bitsPerPixel = ImageFormat.getBitsPerPixel(ImageFormat.NV21);
long sizeInBits = previewSize.getHeight() * previewSize.getWidth() * bitsPerPixel;
int bufferSize = (int) Math.ceil(sizeInBits/8.0d) + 1;
//
// NOTICE: This code only works when using play services v. 8.1 or higher.
//
// Creating the byte array this way and wrapping it, as opposed to using .allocate(),
// should guarantee that there will be an array to work with.
byte[] byteArray = new byte[bufferSize];
ByteBuffer buffer = ByteBuffer.wrap(byteArray);
if (!buffer.hasArray() || (buffer.array() != byteArray)) {
// I don't think that this will ever happen. But if it does, then we wouldn't be
// passing the preview content to the underlying detector later.
throw new IllegalStateException("Failed to create valid buffer for camera source.");
}
mBytesToByteBuffer.put(byteArray, buffer);
return byteArray;
}
CRASHのDEVICE INFO
'bufferSize'の値は何ですか? – Carcigenicate
@Carcigenicate実際にこのコードはhttps://github.com/googlesamples/android-vision/blob/master/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/にあります。 vision/barcodereader/ui/camera/CameraSource.java from line 1030 –
@Carcigenicate私はそれがアンドロイドデバイスの各プレビューサイズに依存すると思います。 –