防止java中的图像编码

防止java中的图像编码,java,android,Java,Android,我有代码上传图像和文本到服务器,但我的代码编码的图像和在服务器上的图像应该被解码 我想阻止图像编码。我试过一些方法,但都不管用 我不知道怎么做。请帮帮我 这是我的密码: public class Share_food extends Activity { ProgressDialog prgDialog; String encodedString; RequestParams params = new RequestParams(); String imgPath, fileName; Bit

我有代码上传图像和文本到服务器,但我的代码编码的图像和在服务器上的图像应该被解码

我想阻止图像编码。我试过一些方法,但都不管用

我不知道怎么做。请帮帮我

这是我的密码:

public class Share_food extends Activity {

ProgressDialog prgDialog;
String encodedString;
RequestParams params = new RequestParams();
String imgPath, fileName;
Bitmap bitmap;
private static int RESULT_LOAD_IMG = 1;
EditText ti,desc;
TextView tv;
String url="http://example.com/index.php";

@SuppressLint("CutPasteId")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.share_food);
    prgDialog = new ProgressDialog(this);
    prgDialog.setCancelable(false);
    ti= (EditText)findViewById(R.id.title);
    desc=(EditText)findViewById(R.id.share_desc22);

    //getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#3b5998")));
    //getActionBar().setIcon( new ColorDrawable(getResources().getColor(android.R.color.transparent)));
    //getActionBar().setTitle("");
}


public void loadImagefromGallery(View view) {
    Intent galleryIntent = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(galleryIntent, RESULT_LOAD_IMG);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    try {
        if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK
                && null != data) {
            Uri selectedImage = data.getData();
            String[] filePathColumn = { MediaStore.Images.Media.DATA };
            Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            imgPath = cursor.getString(columnIndex);
            cursor.close();
            ImageView imgView = (ImageView) findViewById(R.id.imgView);
            imgView.setImageBitmap(BitmapFactory
                    .decodeFile(imgPath));
            String fileNameSegments[] = imgPath.split("/");
            fileName = fileNameSegments[fileNameSegments.length - 1];
            params.put("filename", fileName);

        } else {
            Toast.makeText(this, "error",
                    Toast.LENGTH_LONG).show();
            imgPath="2";
        }
    } catch (Exception e) {
        Toast.makeText(this, "error...!", Toast.LENGTH_LONG)
                .show();
    }
}

public void uploadImage(View v) {

    if (imgPath != null && !imgPath.isEmpty()) {
        prgDialog.setMessage("process");
        prgDialog.show();
        encodeImagetoString();
    } else {
        prgDialog.setMessage("process");
        prgDialog.show();
        triggerImageUpload();
    }
}

public void encodeImagetoString() {
    new AsyncTask<Void, Void, String>() {
        protected void onPreExecute() {
        };

        @Override
        protected String doInBackground(Void... params) {

            BitmapFactory.Options options = null;
            options = new BitmapFactory.Options();
            options.inSampleSize = 3;
            bitmap = BitmapFactory.decodeFile(imgPath,
                    options);
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.PNG, 50, stream);
            byte[] byte_arr = stream.toByteArray();
            encodedString = Base64.encodeToString(byte_arr, 0);
            return "";
        }

        @Override
        protected void onPostExecute(String msg) {

            prgDialog.setMessage("upload");

            params.put("title", ti.getText().toString().trim());

            //desc
            //params.put("desc",desc.getText().toString().trim());

            params.put("image", encodedString);

            triggerImageUpload();
        }
    }.execute(null, null, null);
}

public void triggerImageUpload() {

    params.put("title", ti.getText().toString().trim());

    //desc
    //params.put("desc", desc.getText().toString().trim());

    makeHTTPCall();
}

public void makeHTTPCall() {
    prgDialog.setMessage("connecting");
    AsyncHttpClient client = new AsyncHttpClient();
    client.post(url,
            params, new AsyncHttpResponseHandler() {

                @Override
                public void onSuccess(String response) {
                    prgDialog.hide();
                    Toast.makeText(getApplicationContext(), "done",
                            Toast.LENGTH_LONG).show();
                }

                @Override
                public void onFailure(int statusCode, Throwable error,
                                      String content) {
                    prgDialog.hide();
                    if (statusCode == 404) {
                        Toast.makeText(getApplicationContext(),
                                "error",
                                Toast.LENGTH_LONG).show();
                    }
                    else if (statusCode == 500) {
                        Toast.makeText(getApplicationContext(),
                                "error",
                                Toast.LENGTH_LONG).show();
                    }
                    else {
                        Toast.makeText(
                                getApplicationContext(),
                                "error !!!"
                                        + statusCode, Toast.LENGTH_LONG)
                                .show();
                    }
                }
            });
}

@Override
protected void onDestroy() {
    super.onDestroy();
    if (prgDialog != null) {
        prgDialog.dismiss();
    }
}
public class Share\u food扩展活动{
进程对话;
字符串编码字符串;
RequestParams params=新的RequestParams();
字符串imgPath,文件名;
位图;
私有静态int结果\加载\ IMG=1;
编辑文本ti,desc;
文本视图电视;
字符串url=”http://example.com/index.php";
@SuppressLint(“CutPasteId”)
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(右布局,共享食物);
prgDialog=新建进度对话框(此对话框);
prgDialog.setCancelable(假);
ti=(EditText)findViewById(R.id.title);
desc=(EditText)findViewById(R.id.share_desc22);
//getActionBar().setBackgroundDrawable(新的ColorDrawable(Color.parseColor(“#3b5998”));
//getActionBar().setIcon(新的ColorDrawable(getResources().getColor(android.R.color.transparent));
//getActionBar().setTitle(“”);
}
公共void loadImagefromGallery(视图){
Intent gallerycontent=新意图(Intent.ACTION\u PICK,
android.provider.MediaStore.Images.Media.EXTERNAL\u CONTENT\u URI);
startActivityForResult(GalleryContent、RESULT\u LOAD\u IMG);
}
@凌驾
受保护的void onActivityResult(int请求代码、int结果代码、意图数据){
super.onActivityResult(请求代码、结果代码、数据);
试一试{
如果(requestCode==RESULT\u LOAD\u IMG&&resultCode==RESULT\u OK
&&空!=数据){
Uri selectedImage=data.getData();
字符串[]filePathColumn={MediaStore.Images.Media.DATA};
Cursor Cursor=getContentResolver().query(selectedImage,
filePathColumn,null,null,null);
cursor.moveToFirst();
int columnIndex=cursor.getColumnIndex(filePathColumn[0]);
imgPath=cursor.getString(columnIndex);
cursor.close();
ImageView imgView=(ImageView)findViewById(R.id.imgView);
imgView.setImageBitmap(位图工厂
.decodeFile(imgPath));
字符串fileNameSegments[]=imgPath.split(“/”);
fileName=fileNameSegments[fileNameSegments.length-1];
参数put(“文件名”,文件名);
}否则{
Toast.makeText(此“错误”,
Toast.LENGTH_LONG).show();
imgPath=“2”;
}
}捕获(例外e){
Toast.makeText(此“错误…”,Toast.LENGTH\u LONG)
.show();
}
}
公共无效上载映像(视图v){
if(imgPath!=null&&!imgPath.isEmpty()){
prgDialog.setMessage(“进程”);
prgDialog.show();
encodeImagetoString();
}否则{
prgDialog.setMessage(“进程”);
prgDialog.show();
triggerImageUpload();
}
}
public void encodeImagetoString(){
新建异步任务(){
受保护的void onPreExecute(){
};
@凌驾
受保护字符串doInBackground(无效…参数){
BitmapFactory.Options=null;
options=新的BitmapFactory.options();
options.inSampleSize=3;
位图=位图工厂.decodeFile(imgPath,
选择权);
ByteArrayOutputStream=新建ByteArrayOutputStream();
compress(bitmap.CompressFormat.PNG,50,流);
byte[]byte_arr=stream.toByteArray();
encodedString=Base64.encodeToString(字节_arr,0);
返回“”;
}
@凌驾
受保护的void onPostExecute(字符串msg){
prgDialog.setMessage(“上传”);
参数put(“title”,ti.getText().toString().trim());
//描述
//参数put(“desc”,desc.getText().toString().trim());
参数put(“图像”,编码字符串);
triggerImageUpload();
}
}.执行(空,空,空);
}
public void triggerImageUpload(){
参数put(“title”,ti.getText().toString().trim());
//描述
//参数put(“desc”,desc.getText().toString().trim());
makeHTTPCall();
}
public void makeHTTPCall(){
prgDialog.setMessage(“连接”);
AsyncHttpClient=新的AsyncHttpClient();
client.post(url,
参数,新的AsyncHttpResponseHandler(){
@凌驾
成功时公共无效(字符串响应){
prgDialog.hide();
Toast.makeText(getApplicationContext(),“完成”,
Toast.LENGTH_LONG).show();
}
@凌驾
public void onFailure(int状态码、可丢弃错误、,
字符串内容){
prgDialog.hide();
如果(状态代码==404){
Toast.makeText(getApplicationContext(),
“错误”,
Toast.LENGTH_LONG).show();
}
否则如果(状态代码==500){
Toast.makeText(getApplicationContext(),
“错误”,
Toast.LENGTH_LONG).show();
}
否则{
Toast.makeText(
getApplicationContext(),
“错误!!!”
+状态码,土司长度(长)
.show();
}
}
});
}
@凌驾
受保护的空onDestroy(){
super.ondestory();
if(prgDialog!=null){
prgDialog.disclose();
}
}

}

您必须在接收端对字符串进行解码并保存解码后的字符串。邮政t