Low picture/image quality when capture from camera

ckng picture ckng · Apr 30, 2012 · Viewed 73.4k times · Source

I have one problem. When I try to get picture from camera, the quality is very low. At first, capture the picture using camera, than save to the directory and at the same time get that picture and show in my app.The picture saved inside directory is a fine quality but when I get it from directory, the quality is low. below is my sample code :

public void onActivityResult(int requestCode, int resultCode, Intent intent) {

    if (requestCode == CAMERA_PIC_REQUEST) {  

        Bitmap thumbnail = (Bitmap) intent.getExtras().get("data");

        if (g==1)
        {
            ImageView myImage = (ImageView) findViewById(R.id.img5);
            myImage.setImageBitmap(thumbnail);

            View a = findViewById(R.id.img5);
            a.setVisibility(View.VISIBLE);

            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, stream);

            byteArray1 = stream.toByteArray();
        }
}

any solution/suggestion? Thanks :)

Solved

The problem solved when I follow the code given by Antrromet below

Answer

Antrromet picture Antrromet · Apr 30, 2012

I have used the following code and this works perfectly fine for me.

            values = new ContentValues();
            values.put(MediaStore.Images.Media.TITLE, "New Picture");
            values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
            imageUri = getContentResolver().insert(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
            startActivityForResult(intent, PICTURE_RESULT);

and also

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {

        case PICTURE_RESULT:
            if (requestCode == PICTURE_RESULT)
                if (resultCode == Activity.RESULT_OK) {
                    try {
                        thumbnail = MediaStore.Images.Media.getBitmap(
                                getContentResolver(), imageUri);
                        imgView.setImageBitmap(thumbnail);
                        imageurl = getRealPathFromURI(imageUri);    
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
        }
    }

and

public String getRealPathFromURI(Uri contentUri) {
        String[] proj = { MediaStore.Images.Media.DATA };
        Cursor cursor = managedQuery(contentUri, proj, null, null, null);
        int column_index = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    }