5

I read many posts there? But i don't find correctly answer.

I try do something this:

@Override
public void onPictureTaken(byte[] paramArrayOfByte, Camera paramCamera) {
    try {


        Bitmap bitmap = BitmapFactory.decodeByteArray(paramArrayOfByte, 0,
        paramArrayOfByte.length);

        int width = bitmap.getWidth();
        int height = bitmap.getHeight();

        FileOutputStream os = new ileOutputStream(Singleton.mPushFilePath);

        Matrix matrix = new Matrix();
        matrix.postRotate(90);
        Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width,
            height, matrix, false);

        resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 95, os);
        os.close();
        ...

Is there a way to rotate picture, without using BitmapFactory? I want rotate picture without loss of quality!

ArtKorchagin
  • 4,801
  • 13
  • 42
  • 58

1 Answers1

4

Perhaps you can take the picture already rotated as you desire using Camera.setDisplayOrientation? Check Android camera rotate. Further, investigate Camera.Parameters.setRotation(). One of these techniques should do the trick for you.

Otherwise your code looks fine except for using parameter 95 on Bitmap.compress, you need to use 100 for lossless compression.

To avoid out-of-memory exception, use Camera.Parameters.setPictureSize() to take a lower resolution picture (e.g. 3Mpx). i.e. do you really need an 8Mpx photo? Make sure to use Camera.Parameters.getSupportedPictureSizes() to determine the supported sizes on your device.

Community
  • 1
  • 1
CSmith
  • 13,318
  • 3
  • 39
  • 42
  • 6
    Unfortunately, `setDisplayOrientaion()` only applies to preview and does not effect the buffer captured in `onPicturetaken()`. For an actual solution, please see http://stackoverflow.com/a/18447809/192373 – Alex Cohn Apr 05 '14 at 13:07
  • 2
    setRotation does just that - rotates the actual image you receive in onPictureTaken. – slott May 19 '15 at 06:38