小编Ale*_*use的帖子

通过蓝牙将图像从 ESP32 发送到 Android Studio 时“丢失字节”

第一次在这里提问。目前,我在将 ESP32 CAM 拍摄的照片发送到 Android Studio 应用程序时遇到问题。

虽然图片已收到,但大多数时候并不完整,或者显示一些灰色区域,如附图所示。

我注意到可用字节因图片而异,因此我绝望地尝试循环输出/输入流来拍照,直到可用字节超过 14000。仍然有大量可用字节,图片多次(并非总是如此) )显示一大块灰色像素。

我读到这可能是因为蓝牙套接字必须在“最后”异常中关闭,但我无法让它工作。

我非常感谢你的帮助!

private fun tomarFoto() { //Function to take the picture by sending an OutputStream and receiving the taken picture bytes through InputStream
  var bytes : ByteArray? = null
  val fotoEsp : ImageView = findViewById(R.id.fotoESP)
  var available = 0

  if (m_bluetoothSocket != null) {
    try {
      CoroutineScope(IO).launch {
        for (i in 0..4) {
          async {            
            m_bluetoothSocket!!.outputStream.write("a".toByteArray())
            delay(1500)
          }.await()

          available = m_bluetoothSocket!!.inputStream.available()
          println("Available1: ${available}")
          if (available > 14000) {
            break …
Run Code Online (Sandbox Code Playgroud)

android image bluetooth kotlin esp32

5
推荐指数
1
解决办法
761
查看次数

标签 统计

android ×1

bluetooth ×1

esp32 ×1

image ×1

kotlin ×1