0

I've been developed app to take a picture to be saved in gallery. I've searched online and the easiest way that I could practice was to use data.getExtras().get("data") . So below are the code to take picture from camera. Note that I'm using fragment in this class.

img22a1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(intent,CAMERA_01);
        }
    });

Get the captured image and convert it to string

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == CAMERA_01) {
        if (resultCode == Activity.RESULT_OK) {
            Bitmap bitmap = (Bitmap) data.getExtras().get("data");
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, output);
            byte[] byte_arr = output.toByteArray();
            ((SiteProgress) getActivity().getApplication()).seti22a1(Base64.encodeToString(byte_arr, Base64.DEFAULT));
            BitmapDrawable ob = new BitmapDrawable(getResources(), bitmap);
            img22a1.setBackgroundDrawable(ob);
        } else if (resultCode == Activity.RESULT_CANCELED) {
        }
    }
}

I save the string into global variable so another activity can access it. In another activity, I have a button to save the image into folder/gallery by accessing the image string.

for(int i=0;i<=namefile.length;i++){
            Bitmap[] bitmap = new Bitmap[namefile.length];
            FileOutputStream outputStream = new FileOutputStream(String.valueOf(namefile[i]));
            bitmap[i] = BitmapFactory.decodeByteArray(decodedString[i],0,decodedString[i].length);
            bitmap[i].compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
            outputStream.close();

            MediaStore.Images.Media.insertImage(getActivity().getContentResolver(), namefile[i].getAbsolutePath(), namefile[i].getName(), namefile[i].getName());

        }

It worked to save the image into folder/gallery....But the quality of image was very low...I could barely see text in the image.

They said data.getExtras().get("data") supposed to return thumbnail and not the actual image. What I want here is to get the full image and not the thumbnail one.

Any answer will be very appreciated.

BrenDonie
  • 85
  • 1
  • 10

1 Answers1

1

From: Android - How to get the image using Intent data

if(data != null)
{           
        Uri selectedImageUri = data.getData();
        filestring = selectedImageUri.getPath();

        Bitmap thumbnail = BitmapFactory.decodeFile(filestring, options2);

        System.out.println(String.format("Bitmap(CAMERA_IMAGES_REQUEST): %s", thumbnail));
        System.out.println(String.format("cap_image(CAMERA_IMAGES_REQUEST): %s", cap_image));
        cap_image.setImageBitmap(thumbnail); 
}
linuxatico
  • 1,878
  • 30
  • 43
Alessandro.Vegna
  • 1,262
  • 10
  • 19