【问题标题】:How to send screenshots from C# server to android client?如何将屏幕截图从 C# 服务器发送到 android 客户端?
【发布时间】:2020-06-11 05:38:19
【问题描述】:

我在服务器和 Android 客户端之间创建了套接字连接,并将图像作为字节数组发送,但我找不到在 android 中解码字节数组的方法。

每次我尝试Image = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); 时都会遇到类似的错误

SkAndroidCodec::NewFromStream 返回 null

未知的bmp头格式

【问题讨论】:

标签: c# android sockets bitmap bitmapfactory


【解决方案1】:

屏幕截图数据的格式是否正确?尝试将屏幕截图保存到文件并从文件中读取原始字节并将其发送到服务器。

【讨论】:

  • 我最终将其转换为字符串并使用 base64 进行编码,反之亦然。它就像一个魅力。谢谢大家的回答?
【解决方案2】:

希望我正确理解了您的问题,请尝试此方法。

private static Bitmap getBitmapFromString(String jsonString) {
    byte[] decodedString = Base64.decode(jsonString, Base64.DEFAULT);
    Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
    return decodedByte;
}

【讨论】:

  • 如果字节数组仍然包含位图,那将无济于事。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-02
  • 2011-08-15
  • 2012-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多