在服务器上上传5个摄像机图像时,图像在android中变得模糊

时间:2018-07-24 11:58:33

标签: java android

 public byte[] getFileDataFromDrawable(Bitmap bitmap) {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();


        Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmap, 600, 1200, true);
        bitmap.recycle();
        bitmap = resizedBitmap;


        bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);


        return byteArrayOutputStream.toByteArray();
    }

 private void uploadBitmap(final Bitmap bitmap) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ManageLeadActivity.this);
        String companynURL=preferences.getString("companynURL","");
        final ProgressDialog loading = ProgressDialog.show(ManageLeadActivity.this,"Loading...","Please wait...",false,false);
        String url 
        VolleyMultipartRequest volleyMultipartRequest = new VolleyMultipartRequest(Request.Method.POST,url ,
                new Response.Listener<NetworkResponse>() {
                    @Override
                    public void onResponse(NetworkResponse response) {
                        Log.e("dshgjdsfv",""+response);
                        loading.dismiss();
                        try {
                            JSONObject obj = new JSONObject(new String(response.data));
                            Log.e("dshgjdsfv",""+obj);

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        loading.dismiss();
                        Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                }) {


            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> params = new HashMap<>();
                params.put("rep_id", rep_id);
                params.put("contact_id", contact_id);
                Log.e("vshhfvv",""+params);
                return params;
            }

            /*
             * Here we are passing image by renaming it with a unique name
             * */
            @Override
            protected Map<String, DataPart> getByteData() {
                Map<String, DataPart> params = new HashMap<>();
                long imagename = System.currentTimeMillis();
                params.put("uploaded_file", new DataPart(imagename + ".png", getFileDataFromDrawable(bitmap)));
                return params;
            }
        };

        Volley.newRequestQueue(this).add(volleyMultipartRequest);
    }

0 个答案:

没有答案