Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is normal for the default camera application. The way to get the full size image is to tell the camera activity to put the result into a file. First create a file and then start the camera application as follows:</p> <pre><code>outputFileName = createImageFile(".tmp"); Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(outputFileName)); startActivityForResult(takePictureIntent, takePhotoActionCode); </code></pre> <p>Then in your onActivityResult, you can get this image file back and manipulate it.</p> <pre><code>@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == takePhotoActionCode) { if (resultCode == RESULT_OK) { // NOTE: The intent returned might be NULL if the default camera app was used. // This is because the image returned is in the file that was passed to the intent. processPhoto(data); } } } </code></pre> <p>processPhoto will look a bit like this:</p> <pre><code> protected void processPhoto(Intent i) { int imageExifOrientation = 0; // Samsung Galaxy Note 2 and S III doesn't return the image in the correct orientation, therefore rotate it based on the data held in the exif. try { ExifInterface exif; exif = new ExifInterface(outputFileName.getAbsolutePath()); imageExifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); } catch (IOException e1) { e1.printStackTrace(); } int rotationAmount = 0; if (imageExifOrientation == ExifInterface.ORIENTATION_ROTATE_270) { // Need to do some rotating here... rotationAmount = 270; } if (imageExifOrientation == ExifInterface.ORIENTATION_ROTATE_90) { // Need to do some rotating here... rotationAmount = 90; } if (imageExifOrientation == ExifInterface.ORIENTATION_ROTATE_180) { // Need to do some rotating here... rotationAmount = 180; } int targetW = 240; int targetH = 320; BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; BitmapFactory.decodeFile(outputFileName.getAbsolutePath(), bmOptions); int photoWidth = bmOptions.outWidth; int photoHeight = bmOptions.outHeight; int scaleFactor = Math.min(photoWidth/targetW, photoHeight/targetH); bmOptions.inJustDecodeBounds = false; bmOptions.inSampleSize = scaleFactor; bmOptions.inPurgeable = true; Bitmap scaledDownBitmap = BitmapFactory.decodeFile(outputFileName.getAbsolutePath(), bmOptions); if (rotationAmount != 0) { Matrix mat = new Matrix(); mat.postRotate(rotationAmount); scaledDownBitmap = Bitmap.createBitmap(scaledDownBitmap, 0, 0, scaledDownBitmap.getWidth(), scaledDownBitmap.getHeight(), mat, true); } ImageView iv2 = (ImageView) findViewById(R.id.photoImageView); iv2.setImageBitmap(scaledDownBitmap); FileOutputStream outFileStream = null; try { mLastTakenImageAsJPEGFile = createImageFile(".jpg"); outFileStream = new FileOutputStream(mLastTakenImageAsJPEGFile); scaledDownBitmap.compress(Bitmap.CompressFormat.JPEG, 75, outFileStream); } catch (Exception e) { e.printStackTrace(); } } </code></pre> <p>One thing to note is that on Nexus devices the calling activity is not normally destroyed. However on Samsung Galaxy S III and Note 2 devices the calling activity is destroyed. Therefore the just storing the outputFileName as a member variable in the Activity will result in it being null when the camera app returns unless you remember to save it when the activity dies. It's good practice to do that anyhow, but this is a mistake that I've made before so I thought I'd mention it.</p> <p><strong>EDIT:</strong></p> <p>Regarding your comment, the createImageFile is a not in the standard API, it's something I wrote (or I may have borrowed :-), I don't remember), here is the method for createImageFile():</p> <pre><code> private File createImageFile(String fileExtensionToUse) throws IOException { File storageDir = new File( Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES ), "MyImages" ); if(!storageDir.exists()) { if (!storageDir.mkdir()) { Log.d(TAG,"was not able to create it"); } } if (!storageDir.isDirectory()) { Log.d(TAG,"Don't think there is a dir there."); } // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "FOO_" + timeStamp + "_image"; File image = File.createTempFile( imageFileName, fileExtensionToUse, storageDir ); return image; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload