0

I am learning Upload image to server where image taked from gallery or camera android ....

When i show image after take from gallery or camera to imageview with image decode, image not blur... but after i upload, image like be small size and blurred ..

I do not know, where is the mistake. whether on the decoded image or upload image

here part of my code

decode code

public void decodeFile(String filePath) {
    // Decode image size
    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(filePath, o);

    // The new size we want to scale to
    final int REQUIRED_SIZE = 1024;

    // Find the correct scale value. It should be the power of 2.
    int width_tmp = o.outWidth, height_tmp = o.outHeight;
    int scale = 1;
    while (true) {
        if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE)
            break;
        width_tmp /= 2;
        height_tmp /= 2;
        scale *= 2;
    }

    // Decode with inSampleSize
    BitmapFactory.Options o2 = new BitmapFactory.Options();
    o2.inSampleSize = scale;
    bitmap = BitmapFactory.decodeFile(filePath, o2);

    imgView.setImageBitmap(bitmap);

}

upload code

try {

            DatabaseHandler userDB = new DatabaseHandler(getApplicationContext());      
            HashMap<String, String> userDetail = userDB.getUserDetails();
            String uid= userDetail.get("uid");  

            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            bitmap.compress(CompressFormat.JPEG, 100, bos);
            byte[] data = bos.toByteArray();
            HttpClient httpClient = new DefaultHttpClient();                
            HttpPost postRequest = new HttpPost(PHP_URL);               
            ByteArrayBody bab = new ByteArrayBody(data,file_name);              
            MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
            reqEntity.addPart("uploadedfile", bab);
            postRequest.setEntity(reqEntity);
            HttpResponse response = httpClient.execute(postRequest);
            BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(),"UTF-8"));
            String sResponse;
            StringBuilder s = new StringBuilder();

            while ((sResponse = reader.readLine()) != null) {
                s = s.append(sResponse);
            }

            return s.toString().trim();

        } catch (Exception e) {

            err="error"+e.getMessage();
            Log.e(e.getClass().getName(), e.getMessage());

            return e.getMessage();
        }   

before upload, image show in ImageView enter image description here

After upload, and show in listview enter image description here

I hope anyone can help me. Sorry if my English is not good ...

bukanamay
  • 577
  • 5
  • 11
  • 26

1 Answers1

-1

According to method documentation you are compressing image 100 percent which degrades the quality

        bitmap.compress(CompressFormat.JPEG, 100, bos);

i suggest using a smaller value than 100 and adjusting till you get a balance between quality and size

Shubhank
  • 21,721
  • 8
  • 65
  • 83