0

I have an app that capture image, show it and then send it to web server (with web service). The problem is that the image quality is very low (about 100px), and i can't find why is it happened.

Here is my code:

The button that open the camera:

cameraBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(intent, CAMERA_REQUEST);
        }
    });

Show the image:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
        Bitmap bitmap = (Bitmap) data.getExtras().get("data");
        tmpImg.setImageBitmap(bitmap);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
        byte[] imageInByte = baos.toByteArray();

        dialog = ProgressDialog.show(MainActivity.this, "", "Uploading file...", true);
        sendFile(imageInByte); // send the file to server
    }
}

Any ideas?

Mr Lord
  • 150
  • 1
  • 4
  • 18
  • 1
    Because you are compressing your image by using `bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);` in your `onActivityResult` – UltimateDevil Sep 21 '17 at 09:09
  • So how can i do it without compressing it? do you have an example code? – Mr Lord Sep 21 '17 at 09:11
  • if u are sending image to your server then you can convert your image into `Base64 String` and send this string to your server and at server site you can create this String to image again – UltimateDevil Sep 21 '17 at 09:13

1 Answers1

0

bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); did the quality issues. You have to look lossy compression techniques in order to get picture quality. Please refer the following link: https://developer.android.com/topic/performance/network-xfer.html

dmp
  • 66
  • 9