0

私は Android アプリを作成しており、ライブラリから画像を読み込む機能をユーザーに提供しています。

画像は読み込まれていますが、90 度回転しています。-90 度回転することもあります。ライブラリで表示したときに表示される「同じ方法」で画像をロードするにはどうすればよいですか? したがって、回転している場合は、必ず回転させてロードしてください。しかし、それが正しい場合は、同じ方法でロードする必要があります

どうもありがとうございました

申し訳ありませんが、コードを追加する必要がありました。これは次のとおりです。

        try {
            Intent choosePictureIntent = new Intent(Intent.ACTION_PICK, Images.Media.INTERNAL_CONTENT_URI);
            startActivityForResult(choosePictureIntent, REQUEST_CHOOSE_IMAGE);
        } catch (Exception e) {
            e.printStackTrace();
        }
        break;
@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { 
        super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 

        switch(requestCode) { 
        case REQUEST_CHOOSE_IMAGE:
            if(resultCode == RESULT_OK){  
                Uri selectedImage = imageReturnedIntent.getData();
                InputStream imageStream;
                try {
                    imageStream = getContentResolver().openInputStream(selectedImage);
                    BitmapFactory.Options options=new BitmapFactory.Options();
                    options.inSampleSize = 8;
                    Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream, null, options );
                    ivPictureChosen.setImageBitmap(yourSelectedImage); //ivPictureChosen is image view to display the picture

                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    Toast.makeText(this, "Couldn't pick image", Toast.LENGTH_SHORT).show();
                }

        }
    }
}
4

1 に答える 1

0

以下のコードを試しています。画像の向きを調べて、それに応じて回転させます。私が抱えている問題はメモリ不足であり、VM バゲットを超える解決策をまだ見つけていません。これは、小さな画像で、アプリがまだ多くのメモリを使用していない場合に機能するはずです。

ExifInterface ei = new ExifInterface(filePath);
                int orientation = ei.getAttributeInt(
                        ExifInterface.TAG_ORIENTATION,
                        ExifInterface.ORIENTATION_NORMAL);

                switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    rotateBitmap(bitmap, 90);
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    rotateBitmap(bitmap, 180);
                    break;

                }

public static void rotateBitmap(final Bitmap source, int mRotation){
    int targetWidth=source.getWidth();
    int targetHeight=source.getHeight();
    Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, source.getConfig());
    Canvas canvas = new Canvas(targetBitmap);
    Matrix matrix = new Matrix();
    matrix.setRotate(mRotation,source.getWidth()/2,source.getHeight()/2);
    canvas.drawBitmap(source, matrix, new Paint());
}
于 2013-02-24T19:22:11.610 に答える