mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-25 03:11:10 +01:00
Add ability to scan username qr from gallery.
This commit is contained in:
committed by
Alex Hart
parent
6104ef62df
commit
86afa988a0
@@ -1,5 +1,6 @@
|
||||
package org.signal.qr
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import androidx.camera.core.ImageProxy
|
||||
import com.google.zxing.BinaryBitmap
|
||||
import com.google.zxing.ChecksumException
|
||||
@@ -8,10 +9,12 @@ import com.google.zxing.FormatException
|
||||
import com.google.zxing.LuminanceSource
|
||||
import com.google.zxing.NotFoundException
|
||||
import com.google.zxing.PlanarYUVLuminanceSource
|
||||
import com.google.zxing.RGBLuminanceSource
|
||||
import com.google.zxing.Result
|
||||
import com.google.zxing.common.HybridBinarizer
|
||||
import com.google.zxing.qrcode.QRCodeReader
|
||||
import org.signal.core.util.logging.Log
|
||||
import java.nio.IntBuffer
|
||||
|
||||
/**
|
||||
* Wraps [QRCodeReader] for use from API19 or API21+.
|
||||
@@ -35,6 +38,16 @@ class QrProcessor {
|
||||
return getScannedData(PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height, false))
|
||||
}
|
||||
|
||||
fun getScannedData(bitmap: Bitmap?): String? {
|
||||
if (bitmap == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
val buffer = IntBuffer.allocate((bitmap.byteCount / 4) + 1)
|
||||
bitmap.copyPixelsToBuffer(buffer)
|
||||
return getScannedData(RGBLuminanceSource(bitmap.width, bitmap.height, buffer.array()))
|
||||
}
|
||||
|
||||
private fun getScannedData(source: LuminanceSource): String? {
|
||||
try {
|
||||
if (source.width != previousWidth || source.height != previousHeight) {
|
||||
|
||||
Reference in New Issue
Block a user