如何将System.Byte []转换为位图?

劳拉·萨拉瓦(Laura Saraiva)

我正在为学校工作,但是图像有问题。我从Web服务获得System.Byte [],并且尝试了几种解决方案,但无法转换为位图并添加我的ImageView。在我的数据库中,出现“图像”列。有人能帮我吗?谢谢

这是我的android代码。

private String NAMESPACE = "http://tempuri.org/";
private String URL = "http://X.X.X.X/ProjetoFinal/WSGestao.asmx?WSDL";
private String METHOD_NAME = "List_Images";
private String SOAP_ACTION = "http://tempuri.org/List_Images";
private String[] List;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.list_layout);

    new MyAsyncTask().execute();

}

private class MyAsyncTask extends AsyncTask<Void,Void,String[]> {

    protected String[] doInBackground(Void... strings) {

        //connection to the web service
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.debug = true;

        try {
            androidHttpTransport.call(SOAP_ACTION, envelope);
            SoapObject response = (SoapObject) envelope.getResponse();

            //Fetch the server's response and add the list
            List = new String[response.getPropertyCount()];

            for (int i = 0; i < response.getPropertyCount(); i++) {

                List[i] = response.getProperty(i).toString();

            }
        } catch (Exception e) {
            e.printStackTrace();
        }


        return List;
    }


    @Override
    protected void onPostExecute(String[] result) {
        super.onPostExecute(result);


        //convert to Bitmap

    }
}

Web服务发送:

<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/">
<string>System.Byte[]</string>
<string>System.Byte[]</string>
<string>System.Byte[]</string>
<string>System.Byte[]</string>
<string>System.Byte[]</string>
<string>System.Byte[]</string>
<string>System.Byte[]</string>
<string>System.Byte[]</string>
</ArrayOfString>
驱逐舰
  public static void setImageViewWithByteArray(ImageView view, Byte[] data) {
        Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
        view.setImageBitmap(bitmap);
    }

使用此代码在imageView上显示字节[]

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章