1

when i capture image from mobile camera and save it to local storage its quality is fine but when i get this image in my android app image quality to much down even unable to read text in the picture.how i get image in application in android app without losing the quality of picture.

First Activity

    public class MainActivity extends AppCompatActivity {
    static final int REQUEST_IMAGE_CAPTURE = 1;
    ImageButton imageButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        imageButton = findViewById(R.id.camera);

        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                if(takePictureIntent.resolveActivity(getPackageManager()) != null){
                    startActivityForResult(takePictureIntent,REQUEST_IMAGE_CAPTURE);
                }
            }
        });

    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == Activity.RESULT_OK) {

            Bitmap photo = (Bitmap) data.getExtras().get("data");


            //ByteArrayOutputStream stream = new ByteArrayOutputStream();

            //photo.compress(Bitmap.CompressFormat.PNG,100 , stream);

            //byte[] byteArray = stream.toByteArray();

            Intent i = new Intent(MainActivity.this,PrintActivity.class);
            i.putExtra("image",photo);
            startActivity(i);
        }
    }
}

Second Activity

public class PrintActivity extends AppCompatActivity {
ImageView imageView;
Bitmap bmp;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_print);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    imageView = findViewById(R.id.imageViewer);

   // byte[] byteArray = getIntent().getByteArrayExtra("image");
    //bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);

    bmp = getIntent().getParcelableExtra("image");

    imageView.setImageBitmap(bmp);

}

public void btnOnClickPrint(View v){
    PrintHelper printHelper = new PrintHelper(this);
    printHelper.setScaleMode(PrintHelper.SCALE_MODE_FIT);
    printHelper.printBitmap("Image Print",bmp);
}
}
Phantômaxx
  • 37,352
  • 21
  • 80
  • 110
Hamza Shahid Ali
  • 194
  • 3
  • 14
  • Possible duplicate of [Low picture/image quality when capture from camera](https://stackoverflow.com/questions/10377783/low-picture-image-quality-when-capture-from-camera) – krishank Tripathi Mar 10 '18 at 09:55

1 Answers1

0
Bitmap photo = (Bitmap) data.getExtras().get("data");

That is only a thumbnail of the original picture.

So what ever you do it will stay a thumbnail.

You should use that camera intent differently. Indicate where the camera app should save the full picture (Use EXTRA_STREAM) and then tell that path to the second activity so it can load the original picture.

greenapps
  • 11,036
  • 2
  • 14
  • 19