1

カメラを使用しようとしていますが、高品質の画像をキャプチャして保存できましたが、カメラが横向きモードの場合のみです。

横向きと縦向きモードで低品質の画像をキャプチャして保存することもできました.

ポートレートモードで撮影した写真をマトリックスオブジェクトを使って回転させ、うまく保存しました。

ポートレート モードで高品質の画像をキャプチャしようとすると、問題が発生します。キャプチャした画像を回転させようとすると、うまくいかないようです。

ここに私のソースコードがあります:

public void onPictureTaken(byte[] arg0, Camera arg1) {

  // Test if the devicxe is in Portrait mode 

  if (FullscreenActivity.this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {

  // Create a Bitmap from byte []
    Bitmap bitmapPicture = BitmapFactory.decodeByteArray(arg0, 0,
        arg0.length);

    // Create a Matrix, rotate the image and create a new one Bitmap
    Matrix rotateMatrix = new Matrix();
    rotateMatrix.postRotate(90);
    Bitmap rotatedBitmap = Bitmap.createBitmap(bitmapPicture, 0, 0,
        bitmapPicture.getWidth(), bitmapPicture.getHeight(),
        rotateMatrix, false);

    // resize bitmap
    Bitmap resized = Bitmap.createScaledBitmap(rotatedBitmap, 1024, 768, true);

    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    resized.compress(CompressFormat.JPEG, 100, bos);

    // convert new compressed bitmap in a byte []
    byte[] array = bos.toByteArray();

    Uri uriTarget = getContentResolver().insert(
        Media.EXTERNAL_CONTENT_URI, new ContentValues());

    OutputStream imageFileOS;
    try {
      imageFileOS = getContentResolver().openOutputStream(
          uriTarget);
      imageFileOS.write(array);
      imageFileOS.flush();
      imageFileOS.close();
      Toast.makeText(FullscreenActivity.this,
          "Image saved: " + uriTarget.toString(),
          Toast.LENGTH_LONG).show();

    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
4

0 に答える 0