2

我必须参考 id 从服务器检索所有大小的图像到 android 手机,所以我尝试使用下面的编码并成功获取 base 64 字符串并检索到等效 base64string 的图像它适用于小尺寸图像但是当我去对于大尺寸图像,它仍然是黑屏,无法通过这种方法在屏幕上获得大尺寸图像。

提前致谢。

如何找回

通过来自服务器的肥皂对象的大尺寸 base64 字符串

package com.imageload;

import java.io.IOException;
import java.util.StringTokenizer;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Base64;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class ImageloadActivity extends Activity {
    /** Called when the activity is first created. */

    private Button submit,clr,ext;
    private ImageView imageView;
    private TextView institute,orderno,name,mobno,handeled,regdat,delvdat,pname,pamt,dirby,regby,delby;

    String val11,val12,val13,val14;
    String str = null,str2 = null;
    String error="0",IiD;


/*  private static final String SOAP_ACTION = "http://tempuri.org/sta1";
    private static final String METHOD_NAME = "sta1";
    private static final String NAMESPACE = "http://tempuri.org/";
    private static final String URL = "http://cyberstudents.in/newand//service.asmx";*/


    private static final String SOAP_ACTION = "http://tempuri.org/IMAGE";
    private static final String METHOD_NAME = "IMAGE";
    private static final String NAMESPACE = "http://tempuri.org/";
    //private static final String URL = "http://cyberstudents.in/crdroid//service.asmx";
    private static final String URL = "http:///localdb/Service.asmx";


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


        this.orderno=(TextView)this.findViewById(R.id.ordernoeditText);
        this.pname=(TextView)this.findViewById(R.id.insTextView);
        this.submit=(Button)this.findViewById(R.id.getbutton);
        this.clr=(Button)this.findViewById(R.id.clearbutton);
        this.ext=(Button)this.findViewById(R.id.Exitbutton);
        this.imageView =(ImageView) findViewById(R.id.imageView1);

        orderno.setText("CB2-1112-CEA0883");


        this.submit.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub


                               IiD=orderno.getText().toString();    


                                if(error.equals("0"))
                                {
                                    SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
                                    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                                    envelope.dotNet=true;

                                    request.addProperty("ID",IiD);                                                                              
                                    envelope.setOutputSoapObject(request);
                                    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);



                                        try
                                        {
                                            try 
                                            {
                                                androidHttpTransport.call(SOAP_ACTION, envelope);


                                            } 
                                            catch (XmlPullParserException e)
                                            {
                                                // TODO Auto-generated catch block
                                                e.printStackTrace();
                                            }   

                                            SoapPrimitive result =  (SoapPrimitive)envelope.getResponse();
                                            //to get the data should be a base
                                            String resultData = result.toString();

                                            //pname.setText(resultData);

                                            byte[] decodedString = Base64.decode(resultData, Base64.DEFAULT);
                                            Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
                                            imageView.setImageBitmap(decodedByte);


                                        } 
                                        catch (IOException e)
                                        {
                                            // TODO Auto-generated catch block
                                            e.printStackTrace();
                                        }

                                    }

                }
        });


        this.clr.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub

                pname.setText("");


            }
        });

        this.ext.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                System.exit(0);
            }
        });





    }
}

当返回大于 150kb 或 2500*3000 尺寸的图像大小时,soapprimitive(result) 返回 null

[WebMethod]
    public string  IMAGE(string ID)
    {

SqlConnection conn = new SqlConnection("Data Source=;Initial Catalog=;Persist Security Info=True;User ID=sa;");
        conn.Open();
        SqlDataAdapter sdImageSource = new SqlDataAdapter();
        sdImageSource.SelectCommand = new SqlCommand("select ImageData from ImagesStore where ImageId=('" + ID + "')", conn);
        DataSet dsImage = new DataSet();
        sdImageSource.Fill(dsImage);
        byte[] blob = (byte[])dsImage.Tables[0].Rows[0][0];
        int k = blob.Length;
        string c = Convert.ToBase64String(blob);
        return c;
}
4

1 回答 1

3

我的建议是将 Base64 图像存储在服务器文件夹中并将其路径保存在数据库中,以便您轻松检索它

于 2012-06-01T12:22:29.413 回答