android - 使用 k-soap2 在 Android 中读取字节数组

标签 android bitmap arrays ksoap2

我在 .net 网络服务中使用这段代码将图像作为字节数组发送:

public byte[] getImage()
{
    byte[] img;
    ....
    return img;
}

如何使用 ksoap2 读取这个字节数组并将其转换为位图?

你能用简单的代码解释一下吗?

更新: 我在 android 中使用这段代码从网络服务读取数据:

        String SOAP_ACTION = WebServiceNameSpace + GetImage;
        String NAMESPACE = WebServiceNameSpace;
        String METHOD_NAME = GetImage;
        String URL = WS_URL;

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        SoapSerializationEnvelope Envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        Envelope.dotNet = true;
        Envelope.setOutputSoapObject(request);
        HttpTransportSE transport = new HttpTransportSE(URL);
        transport.call(SOAP_ACTION, Envelope);
        SoapPrimitive primetive = (SoapPrimitive) Envelope.getResponse();
        return primetive.toString();

最佳答案

考虑到您已成功使用 Web 服务并检索到字节,您需要做的就是解码数据并从中检索 Bitmap:

final SoapPrimitive primitive = (SoapPrimitive) Envelope.getResponse();
final String imgData = primitive.toString();
if (imgData != "") 
{
    byte[] imgBytes = Base64.decode(imgData, Base64.DEFAULT);         
    final Bitmap bitmap = BitmapFactory.decodeByteArray(imgBytes, 0, imgBytes.length);
    // TODO: set this bitmap into an ImageView or handle it as you wish
}

如果解码部分有问题,请引用this answer and its links也是。

关于android - 使用 k-soap2 在 Android 中读取字节数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27599769/

相关文章:

android - 在 Android 测试中,如何检查是否显示了 View ?

存储带引号的字符串时 Android SharedPreferences 崩溃

android - Play 商店中的广告部分为空

java - Android 位图重用

javascript - JavaScript 数组长度的错误表示

android - 我可以从 Android 中的 Thread.UncaughtExceptionHandler 类开始一个 Activity 吗?

c# - 从(切孔到)图像中反转裁剪

java - 如何正确设置用户选择的文件夹中图像的 Uri 以在 ImageView 中显示?

javascript - 如何在mongodb中使用自动生成的id查找数组元素

C:结构数组(在结构数组中输入 int 数组)