Note that there are some explanatory texts on larger screens.

plurals
  1. POcode to rotate image captured by camera intent not working in Android
    primarykey
    data
    text
    <p>I have a problem that my image captured using camera intent gets rotated, which I asked at <a href="https://stackoverflow.com/questions/14066038/why-image-captured-using-camera-intent-gets-rotated-on-some-devices-in-android">Why does an image captured using camera intent gets rotated on some devices on Android?</a></p> <p>So as per the suggested answers there, I'm now trying to rotate the image which I get using camera(I have used camera intent). My code is,</p> <pre><code>public class SimpleCameraActivity extends Activity { private static final int TAKE_PICTURE = 1888; private Uri imageUri; ImageView imageView; Bitmap bitmap; Button btnOK, btnDiscard; RelativeLayout rLButtons; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.simple_camera); imageView = (ImageView) findViewById(R.id.image_view_sc); captureImage(); } public void captureImage() { Intent intentCamera = new Intent("android.media.action.IMAGE_CAPTURE"); File filePhoto = new File(Environment.getExternalStorageDirectory(), "Pic.jpg"); imageUri = Uri.fromFile(filePhoto); MyApplicationGlobal.imageUri = imageUri.getPath(); intentCamera.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); startActivityForResult(intentCamera, TAKE_PICTURE); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent intentFromCamera) { super.onActivityResult(requestCode, resultCode, intentFromCamera); if (resultCode == RESULT_OK &amp;&amp; requestCode == TAKE_PICTURE) { if (intentFromCamera != null) { Bundle extras = intentFromCamera.getExtras(); if (extras.containsKey("data")) { bitmap = (Bitmap) extras.get("data"); } else { bitmap = getBitmapFromUri(); } } else { bitmap = getBitmapFromUri(); } checkForRotation(); //rotateImage(); //rotateImage1(); rotateImage3(); //imageView.setImageBitmap(bitmap); // imageView.setImageURI(imageUri); } else { finish(); } } public void rotateImage() { Bitmap targetBitmap = Bitmap.createBitmap(100, 80, bitmap.getConfig()); Canvas canvas = new Canvas(targetBitmap); Matrix matrix = new Matrix(); matrix.setRotate(180, bitmap.getWidth() / 2, bitmap.getHeight() / 2); matrix.setRotate(90); canvas.drawBitmap(bitmap, matrix, new Paint()); imageView.setImageBitmap(bitmap); } public void rotateImage1() { Matrix matrix = new Matrix(); matrix.setRotate(90, bitmap.getWidth() / 2, bitmap.getHeight() / 2); RectF rectF = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight()); matrix.mapRect(rectF); Bitmap targetBitmap = Bitmap.createBitmap((int) rectF.width(), (int) rectF.height(), bitmap.getConfig()); Canvas canvas = new Canvas(targetBitmap); canvas.drawBitmap(bitmap, matrix, new Paint()); imageView.setImageBitmap(bitmap); } public void rotateImage2() { Matrix mtx = new Matrix(); mtx.reset(); mtx.preTranslate(20, 30); mtx.setRotate((float) 90, 25, 35); mtx.postTranslate(30, 40); Bitmap rotatedBMP = Bitmap.createBitmap(bitmap, 0, 0, 100, 100, mtx, true); this.bitmap = rotatedBMP; imageView.setImageBitmap(bitmap); } public void rotateImage3() { Bitmap bmpOriginal = bitmap; Bitmap targetBitmap = Bitmap.createBitmap((bmpOriginal.getWidth()), (bmpOriginal.getHeight()), Bitmap.Config.ARGB_8888); Paint p = new Paint(); p.setAntiAlias(true); Matrix matrix = new Matrix(); matrix.setRotate((float) 90, (float) (bmpOriginal.getWidth() / 2), (float) (bmpOriginal.getHeight() / 2)); RectF rectF = new RectF(0, 0, bmpOriginal.getWidth(), bmpOriginal.getHeight()); matrix.mapRect(rectF); targetBitmap = Bitmap.createBitmap((int) rectF.width(), (int) rectF.height(), Bitmap.Config.ALPHA_8); Canvas tempCanvas = new Canvas(targetBitmap); tempCanvas.drawBitmap(bmpOriginal, matrix, p); imageView.setImageBitmap(bmpOriginal); } public Bitmap getBitmapFromUri() { getContentResolver().notifyChange(imageUri, null); ContentResolver cr = getContentResolver(); Bitmap bitmap; try { bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, imageUri); return bitmap; } catch (Exception e) { e.printStackTrace(); return null; } } } </code></pre> <p>I have tried different codes rotateImage, 1, 2, 3 etc. But no code is working. rotateImage2() is working, but its badly affecting the quality, so can't use that.</p> <p>I got these code from <a href="https://stackoverflow.com/questions/4166917/android-how-to-rotate-a-bitmap-on-a-center-point">Android: How to rotate a bitmap on a center point</a> and there users say that its working, but not with me. So what wrong I'm doing.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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