Problem z orientacją aparatu w systemie Android


100

Buduję aplikację, która używa aparatu do robienia zdjęć. Oto mój kod źródłowy, aby to zrobić:

        File file = new File(Environment.getExternalStorageDirectory(),
            imageFileName);
    imageFilePath = file.getPath();
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    //Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
    startActivityForResult(intent, ACTIVITY_NATIVE_CAMERA_AQUIRE);

Na onActivityResult()metody używam BitmapFactory.decodeStream()do odbioru obrazu.

Kiedy uruchamiam moją aplikację na Nexusie One, działa dobrze. Ale kiedy uruchomię na Samsungu Galaxy S lub HTC Inspire 4G, kierunek obrazu jest nieprawidłowy.

  • Przechwytuj w trybie portretowym, rzeczywisty obraz (zapisz na karcie SD) zawsze obraca się o 90 stopni.

podgląd obrazu po wykonaniu zdjęcia prawdziwy obraz na karcie SD

Podgląd obrazu po zdjęciu --------- Rzeczywisty obraz na karcie SD

  • Rób zdjęcia w trybie poziomym, wszystko jest w porządku.

Podgląd obrazu po wykonaniu zdjęcia Prawdziwy obraz na karcie SD

Podgląd obrazu po zdjęciu --------- Rzeczywisty obraz na karcie SD


1
setRotation (90) działał u mnie w Samsung Galaxy Nexus, podczas gdy nie obracał obrazu w Xperii S.
StarDust

czy ktoś może mi w tym pomóc? mam ten sam problem stackoverflow.com/questions/28379130/ ...



Odpowiedzi:


50

Jest tu sporo podobnych tematów i problemów. Ponieważ nie piszesz własnego aparatu, myślę, że sprowadza się to do tego:

Niektóre urządzenia obracają obraz przed zapisaniem, podczas gdy inne po prostu dodają znacznik orientacji w danych exif zdjęcia.

Polecam sprawdzić dane exif zdjęcia i poszukać ich szczególnie

ExifInterface exif = new ExifInterface(SourceFileName);     //Since API Level 5
String exifOrientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);

Ponieważ zdjęcie wyświetla się poprawnie w Twojej aplikacji, nie jestem pewien, gdzie jest problem, ale to zdecydowanie powinno skierować Cię na właściwą ścieżkę!


33
Wydaje się, że to nie działa na niektórych urządzeniach, zwraca 0 dla wszystkich orientacji .. Wiem, że dzieje się to na Galaxy S Infuse i Sony Xperia Arc i S II .. Ciekawostką jest to, że gdy te same obrazy są wybierane z galerii , dostawca treści ma odpowiednią wartość orientacyjną. Jakieś pomysły?
Tolga E,

3
@Abhijit Tak, próbowałem rozwiązać ten problem (otworzyłem zgłoszenie z Androidem itd.) I myślę, że znalazłem rozsądne rozwiązanie, aby obsłużyć oba telefony z prawidłowymi i błędnymi informacjami o orientacji. Sprawdź moją szczegółową odpowiedź, którą zamieściłem tutaj na moje własne pytanie; stackoverflow.com/a/8864367/137404
Tolga E

1
@ramz Próbowałem znaleźć to rozwiązanie. ale zwraca 0 dla wszystkich orientacji. Czy masz pojęcie, dlaczego zwraca 0 dla wszystkich orientacji.
Dory,

1
Przyczyną niedziałającego rozwiązania jest czasami niewłaściwa „ścieżka” użyta w konstruktorze ExifInterface. Głównie na KitKat. Zobacz tutaj, jak wybrać właściwą ścieżkę: stackoverflow.com/a/20559175/690777
peter.bartos

1
Zawsze zwraca 0 (ExifInterface.ORIENTATION_UNDEFINED) na moim Samsungu Galaxy S4 ...
valerybodak

28

Właśnie napotkałem ten sam problem i użyłem tego do skorygowania orientacji:

public void fixOrientation() {
    if (mBitmap.getWidth() > mBitmap.getHeight()) {
        Matrix matrix = new Matrix();
        matrix.postRotate(90);
        mBitmap = Bitmap.createBitmap(mBitmap , 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), matrix, true);
    }
}

Jeśli szerokość mapy bitowej jest większa niż wysokość, zwracany obraz jest w orientacji poziomej, więc obracam go o 90 stopni.

Mam nadzieję, że pomoże to komukolwiek innemu z tym problemem.


18
A jeśli zdjęcie zostało faktycznie wykonane w krajobrazie? Twój kod nadal będzie go obracał. To nie jest odpowiedź na pytanie.
Wladimir Palant

1
Moja aplikacja wymusza portret, więc to nie jest problem. Podałem tutaj tylko alternatywne rozwiązanie problemu.

5
Ale jeśli aplikacja wymusza portret, nadal możesz zrobić zdjęcie poziome (szerokość> wysokość) i zostanie ono obrócone ... Tak przynajmniej dostaję ustawienie screenOrientation = "portret" dla wszystkiego ... aparat nadal może robić krajobraz fotki.
Ixx,

pełna i poprawna odpowiedź obecna tutaj stackoverflow.com/questions/6069122/…
Shirish Herwade

21

Potrzebne są dwie rzeczy:

  1. Podgląd aparatu musi być taki sam, jak obrót. Ustaw to przezcamera.setDisplayOrientation(result);

  2. Zapisz zrobione zdjęcie jako podgląd aparatu. Zrób to przez Camera.Parameters.

    int mRotation = getCameraDisplayOrientation();
    
    Camera.Parameters parameters = camera.getParameters();
    
    parameters.setRotation(mRotation); //set rotation to save the picture
    
    camera.setDisplayOrientation(result); //set the rotation for preview camera
    
    camera.setParameters(parameters);
    

Mam nadzieję, że to pomoże.


to jest to! Camera.parameters jest naprawdę wygodny do zapisywania migawek bez renderowania do pośredniej bitmapy
rupps

Oznacz to jako najłatwiejszą odpowiedź! To działa! Bardzo się cieszę z tego łatwego rozwiązania
Kai Burghardt

Jeśli ten fragment zostanie przyjęty w takiej postaci, w jakiej jest, możemy po prostu powiedzieć parameters.setRotation(result), że nie?
Matt Logan

10
Zakłada się, że używasz bezpośrednio klasy Camera, nie możesz określić tych samych opcji, gdy używasz intencji ACTION_IMAGE_CAPTURE.
dach

1
Co to jest result i getCameraDisplayOrientation ()?
venkat

10
            int rotate = 0;
            try {
                File imageFile = new File(sourcepath);
                ExifInterface exif = new ExifInterface(
                        imageFile.getAbsolutePath());
                int orientation = exif.getAttributeInt(
                        ExifInterface.TAG_ORIENTATION,
                        ExifInterface.ORIENTATION_NORMAL);

                switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_270:
                    rotate = 270;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    rotate = 180;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_90:
                    rotate = 90;
                    break;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            Matrix matrix = new Matrix();
    matrix.postRotate(rotate);
    bitmap = Bitmap.createBitmap(bitmap , 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);

przydałoby się trochę wyjaśnienia, co robi twój kod i jak działa inaczej niż inne odpowiedzi (pytanie jest w końcu dość stare, a zatem inne odpowiedzi prawdopodobnie są dość dojrzałe).
kodowanie

7

Inną opcją jest obrócenie mapy bitowej na ekranie wyników w następujący sposób:

ImageView img=(ImageView)findViewById(R.id.ImageView01);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.refresh);
// Getting width & height of the given image.
int w = bmp.getWidth();
int h = bmp.getHeight();
// Setting post rotate to 90
Matrix mtx = new Matrix();
mtx.postRotate(90);
// Rotating Bitmap
Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, w, h, mtx, true);
BitmapDrawable bmd = new BitmapDrawable(rotatedBMP);

img.setImageDrawable(bmd);

30
To podejście nie zadziała, ponieważ obraca również obrazy z urządzeń, które prawidłowo obsługują orientację.
hanspeide

pełna i poprawna odpowiedź obecna tutaj stackoverflow.com/questions/6069122/…
Shirish Herwade

3

Mam też taki sam problem z jakimś urządzeniem:

private void rotateImage(final String path) {

    Bitmap scaledBitmap = Bitmap.createScaledBitmap(Conasants.bm1, 1000,
            700, true);
    Bitmap rotatedBitmap = null;
    try {
        ExifInterface ei = new ExifInterface(path);
        int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);
        Matrix matrix = new Matrix();
        switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            matrix.postRotate(90);
            rotatedBitmap = Bitmap.createBitmap(scaledBitmap, 0, 0,
                    scaledBitmap.getWidth(), scaledBitmap.getHeight(),
                    matrix, true);
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            matrix.postRotate(180);
            rotatedBitmap = Bitmap.createBitmap(scaledBitmap, 0, 0,
                    scaledBitmap.getWidth(), scaledBitmap.getHeight(),
                    matrix, true);
            break;
        case ExifInterface.ORIENTATION_ROTATE_270:
            matrix.postRotate(270);
            rotatedBitmap = Bitmap.createBitmap(scaledBitmap, 0, 0,
                    scaledBitmap.getWidth(), scaledBitmap.getHeight(),
                    matrix, true);
            break;
        default:
            rotatedBitmap = Bitmap.createBitmap(scaledBitmap, 0, 0,
                    scaledBitmap.getWidth(), scaledBitmap.getHeight(),
                    matrix, true);
            break;
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
    cropImage.setImageBitmap(rotatedBitmap);
    rotatedBitmap = null;
    Conasants.bm1 = null;
}

1

Spróbuj w ten sposób: statyczny Uri image_uri; statyczna mapa bitowa taken_image = null;

            image_uri=fileUri; // file where image has been saved

      taken_image=BitmapFactory.decodeFile(image_uri.getPath());
      try
        {
            ExifInterface exif = new ExifInterface(image_uri.getPath()); 

            int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);


            switch(orientation) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    taken_image=decodeScaledBitmapFromSdCard(image_uri.getPath(), 200, 200);
                    RotateBitmap(taken_image, 90);
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    taken_image=decodeScaledBitmapFromSdCard(image_uri.getPath(), 200, 200);
                    RotateBitmap(taken_image, 180);

                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    taken_image=decodeScaledBitmapFromSdCard(image_uri.getPath(), 200, 200);
                    RotateBitmap(taken_image, 270);

                    break;
                case ExifInterface.ORIENTATION_NORMAL:
                    taken_image=decodeScaledBitmapFromSdCard(image_uri.getPath(), 200, 200);
                    RotateBitmap(taken_image, 0);

                    break;
            }

        }
        catch (OutOfMemoryError e)
        {
            Toast.makeText(getActivity(),e+"\"memory exception occured\"",Toast.LENGTH_LONG).show();


        }



public Bitmap RotateBitmap(Bitmap source, float angle) {
      Matrix matrix = new Matrix();
      matrix.postRotate(angle);

      round_Image = source;
      round_Image = Bitmap.createBitmap(source, 0, 0, source.getWidth(),   source.getHeight(), matrix, true);


  return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);

}


1

Koniec z sprawdzaniem danych exif zdjęcia. Idź łatwo z Glide .

Google przedstawił nam bibliotekę Image Loader dla Androida opracowaną przez bumptech o nazwie Glide jako bibliotekę zalecaną przez Google. Do tej pory był używany w wielu projektach open source Google, w tym w oficjalnej aplikacji Google I / O 2014.

Np .: Glide.with (kontekst) .load (uri) .into (widok obrazu);

Więcej: https://github.com/bumptech/glide


1
public void setCameraPicOrientation(){
        int rotate = 0;
        try {
            File imageFile = new File(mCurrentPhotoPath);
            ExifInterface exif = new ExifInterface(
                    imageFile.getAbsolutePath());
            int orientation = exif.getAttributeInt(
                    ExifInterface.TAG_ORIENTATION,
                    ExifInterface.ORIENTATION_NORMAL);

            switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_270:
                    rotate = 270;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    rotate = 180;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_90:
                    rotate = 90;
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        Matrix matrix = new Matrix();
        matrix.postRotate(rotate);
        int targetW = 640;
        int targetH = 640;

        /* Get the size of the image */
        BitmapFactory.Options bmOptions = new BitmapFactory.Options();
        bmOptions.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
        int photoW = bmOptions.outWidth;
        int photoH = bmOptions.outHeight;

        /* Figure out which way needs to be reduced less */
        int scaleFactor = 1;
        if ((targetW > 0) || (targetH > 0)) {
            scaleFactor = Math.min(photoW/targetW, photoH/targetH);
        }

        /* Set bitmap options to scale the image decode target */
        bmOptions.inJustDecodeBounds = false;
        bmOptions.inSampleSize = scaleFactor;
        bmOptions.inPurgeable = true;

        /* Decode the JPEG file into a Bitmap */
        Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
        bitmap= Bitmap.createBitmap(bitmap , 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
            /* Associate the Bitmap to the ImageView */
      imageView.setImageBitmap(bitmap);
    }

Mam nadzieję, że to pomoże !! Dzięki


0
    public static  int mOrientation =  1;

    OrientationEventListener myOrientationEventListener;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.takephoto);

        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);


        myOrientationEventListener
        = new OrientationEventListener(getApplicationContext()) {

            @Override
            public void onOrientationChanged(int o) {
                // TODO Auto-generated method stub
                if(!isTablet(getApplicationContext()))
                {
                    if(o<=285 && o>=80)
                        mOrientation = 2;
                    else
                        mOrientation = 1;
                }
                else
                {
                    if(o<=285 && o>=80)
                        mOrientation = 1;
                    else
                        mOrientation = 2;
                }

            }
        };

        myOrientationEventListener.enable();

    }



    public static boolean isTablet(Context context) {
        return (context.getResources().getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK)
                >= Configuration.SCREENLAYOUT_SIZE_LARGE;
    }

}

Mam nadzieję, że to pomoże. Dzięki!


0

Po prostu napotkam ten sam problem, poniższy fragment kodu działa dla mnie:

private static final String[] CONTENT_ORIENTATION = new String[] {
        MediaStore.Images.ImageColumns.ORIENTATION
};

static int getExifOrientation(ContentResolver contentResolver, Uri uri) {
    Cursor cursor = null;

    try {
        cursor = contentResolver.query(uri, CONTENT_ORIENTATION, null, null, null);
        if (cursor == null || !cursor.moveToFirst()) {
            return 0;
        }
        return cursor.getInt(0);
    } catch (RuntimeException ignored) {
        // If the orientation column doesn't exist, assume no rotation.
        return 0;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

mam nadzieję, że to pomoże :)


0

Spróbuj tego w surfaceChanged callback:

Camera.Parameters parameters=mCamera.getParameters();
if(this.getResources().getConfiguration().orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT){
    parameters.setRotation(90);
}else{
    parameters.setRotation(0);
}
mCamera.setParameters(parameters);

0

// kliknięcie przycisku

btnCamera.setOnClickListener( new View.OnClickListener() {
        @Override
        public void onClick(View view) {

                try {
                    ContentValues values;
                    values = new ContentValues();
                    values.put(MediaStore.Images.Media.TITLE, "New Picture");
                    values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
                    imageUri = context.getContentResolver().insert(
                            MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
                    startActivityForResult(intent, CAMERA_REQUEST);
                }catch (Exception e){}

            });

// metoda onActivityResult

   if (requestCode==CAMERA_REQUEST){
        try {
            if (imageUri!=null) {
                path = String.valueOf(new File(FilePath.getPath(context, imageUri)));
                   }  
        }catch (Exception e){
            toast("please try again "+e.getMessage());
            Log.e("image error",e.getMessage());
        }
    }

// stwórz ścieżkę do pliku klasy

public class FilePath {

public static String getPath(final Context context, final Uri uri) {

    // check here to KITKAT or new version
    final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

    // DocumentProvider
    if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {

        // ExternalStorageProvider
        if (isExternalStorageDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            if ("primary".equalsIgnoreCase(type)) {
                return Environment.getExternalStorageDirectory() + "/"
                        + split[1];
            }
        }
        // DownloadsProvider
        else if (isDownloadsDocument(uri)) {

            final String id = DocumentsContract.getDocumentId(uri);
            final Uri contentUri = ContentUris.withAppendedId(
                    Uri.parse("content://downloads/public_downloads"),
                    Long.valueOf(id));

            return getDataColumn(context, contentUri, null, null);
        }
        // MediaProvider
        else if (isMediaDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            Uri contentUri = null;
            if ("image".equals(type)) {
                contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
            } else if ("video".equals(type)) {
                contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
            } else if ("audio".equals(type)) {
                contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            }

            final String selection = "_id=?";
            final String[] selectionArgs = new String[] { split[1] };

            return getDataColumn(context, contentUri, selection,
                    selectionArgs);
        }
    }
    // MediaStore (and general)
    else if ("content".equalsIgnoreCase(uri.getScheme())) {

        // Return the remote address
        if (isGooglePhotosUri(uri))
            return uri.getLastPathSegment();

        return getDataColumn(context, uri, null, null);
    }
    // File
    else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }

    return null;
}

/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context
 *            The context.
 * @param uri
 *            The Uri to query.
 * @param selection
 *            (Optional) Filter used in the query.
 * @param selectionArgs
 *            (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 */
public static String getDataColumn(Context context, Uri uri,
                                   String selection, String[] selectionArgs) {

    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = { column };

    try {
        cursor = context.getContentResolver().query(uri, projection,
                selection, selectionArgs, null);
        if (cursor != null && cursor.moveToFirst()) {
            final int index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}

/**
 * @param uri
 *            The Uri to check.
 * @return Whether the Uri authority is ExternalStorageProvider.
 */
public static boolean isExternalStorageDocument(Uri uri) {
    return "com.android.externalstorage.documents".equals(uri
            .getAuthority());
}

/**
 * @param uri
 *            The Uri to check.
 * @return Whether the Uri authority is DownloadsProvider.
 */
public static boolean isDownloadsDocument(Uri uri) {
    return "com.android.providers.downloads.documents".equals(uri
            .getAuthority());
}

/**
 * @param uri
 *            The Uri to check.
 * @return Whether the Uri authority is MediaProvider.
 */
public static boolean isMediaDocument(Uri uri) {
    return "com.android.providers.media.documents".equals(uri
            .getAuthority());
}

/**
 * @param uri
 *            The Uri to check.
 * @return Whether the Uri authority is Google Photos.
 */
public static boolean isGooglePhotosUri(Uri uri) {
    return "com.google.android.apps.photos.content".equals(uri
            .getAuthority());
}

}


-1

Kod jest funkcjonalnie dla krajobrazu i portretu @frontCameraID = zmienna uzyskała klasyczną metodę dla kamery pokazowej

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

    if(holder.getSurface() == null) {
        return;
    }
    try{
        camera.stopPreview();
    } catch (Exception e){
    }

    try{

        int orientation = getDisplayOrientation(frontCameraID);

        Camera.Parameters parameters = camera.getParameters();
        parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
        if (parameters.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
            parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
        }

        parameters.setRotation(rotationPicture);
        camera.setParameters(parameters);
        camera.setDisplayOrientation(orientation);
        camera.startPreview();

    } catch (Exception e) {
        Log.i("ERROR", "Camera error changed: " + e.getMessage());
    }
}

Metoda uzyskiwania orientacji obrót y w celu zapisania obrazu i orientacji wyświetlania @result = orientacja w widoku podglądu kamery @rotationPicture = obrót niezbędny do prawidłowego zapisania obrazu

private int getDisplayOrientation(int cameraId) {

    android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
    android.hardware.Camera.getCameraInfo(cameraId, info);
    int rotation = ((Activity) context).getWindowManager().getDefaultDisplay().getRotation();
    int degrees = 0;
    switch (rotation) {
        case Surface.ROTATION_0: degrees = 0; break;
        case Surface.ROTATION_90: degrees = 90; break;
        case Surface.ROTATION_180: degrees = 180; break;
        case Surface.ROTATION_270: degrees = 270; break;
    }

    int result;
    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        result = (info.orientation + degrees) % 360;
        result = (360 - result) % 360;
        rotationPicture = (360 - result) % 360;
    } else {
        result = (info.orientation - degrees + 360) % 360;
        rotationPicture = result;
    }

    return result;
}

Ktoś pyta o kod, proszę powiedz mi.


-2

dwa rozwiązania One line z wykorzystaniem Picassa i biblioteki ślizgowej

Po spędzeniu wielu czasu z wieloma rozwiązaniami problemu rotacji obrazu w końcu znalazłem dwa proste rozwiązania. Nie musimy wykonywać żadnych dodatkowych prac. Picasso i Glide to potężna biblioteka do obsługi obrazów w Twojej aplikacji. Odczyta dane obrazu EXIF ​​i automatycznie obróci obrazy.

Korzystanie z biblioteki glide https://github.com/bumptech/glide

Glide.with(this).load("http url or sdcard url").into(imgageView);

Korzystanie z biblioteki Picasso https://github.com/square/picasso

Picasso.with(context).load("http url or sdcard url").into(imageView);

Witamy w SO. Proszę powstrzymać się od proszenia o głosy za: meta.stackexchange.com/questions/194061/ ...
2017
Korzystając z naszej strony potwierdzasz, że przeczytałeś(-aś) i rozumiesz nasze zasady używania plików cookie i zasady ochrony prywatności.
Licensed under cc by-sa 3.0 with attribution required.