2011-02-28 4 views
0

(Pardonnez-moi si Im obtenir ce totalement faux, je suis un débutant) Je montre quelques photos prises avec MediaStore.ACTION_IMAGE_CAPTURE. J'ai essayé de désactiver autoorientation lorsque la photo est prise, mais il ne semble pas travailler, je l'ai utiliséépargne Rotation Bitmap android

putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION,ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) 

Cela m'a forcé à tourner quelques-unes des photos prises. Je sauvegarde ensuite ces photos sur SDCARD. Mon problème est que je ne veux pas les faire pivoter chaque fois que l'utilisateur charge une photo. J'ai essayé ce code pour créer un nouveau bitmap qui serait sauvegardé dans l'état 'tourné'. Cela a fonctionné sur l'émulateur mais s'est écrasé sur mon HTC. Je suppose que c'est un problème de mémoire. Y a-t-il un moyen de le faire efficacement? Mieux encore, y a-t-il un moyen de désactiver l'autoorientation en prenant des photos avec Camera Intent?

tempBitmap=BitmapFactory.decodeFile(dirPath+filename+".jpg"); 
int tempW = tempBitmap.getWidth(); 
int tempH = tempBitmap.getHeight(); 

if (tempW>tempH) { 
    Matrix mtx = new Matrix(); 
    mtx.postRotate(90); 
    Bitmap rotatedBitmap = Bitmap.createBitmap(Bitmap.createBitmap(tempBitmap, 0, 0, 
                 tempW, tempH, mtx, true)); 

} else{ 
    //... 
} 

Répondre

0

essayez de réduire l'image avec laquelle vous travaillez peut-être un problème de mémoire. Voir ci-dessous pour une solution possible.

BitmapFactory.Options options = new BitmapFactory.Options(); 
options.inSampleSize = 4; //1/4 of the original image 

tempBitmap=BitmapFactory.decodeFile(dirPath+filename+".jpg", options); 
int tempW = tempBitmap.getWidth(); 
int tempH = tempBitmap.getHeight(); 

if (tempW>tempH) { 
    Matrix mtx = new Matrix(); 
    mtx.postRotate(90); 
    Bitmap rotatedBitmap = (tempBitmap, 0,0,tempW, tempH, mtx, true); 
+0

Il pourrait être utile de souligner pourquoi vous pensez que la réduction de l'image est une option. –

1

comme ci-dessus, mais il a oublié un code sur la dernière ligne

BitmapFactory.Options options = new BitmapFactory.Options(); 
options.inSampleSize = 4; //1/4 of the original image 

tempBitmap=BitmapFactory.decodeFile(dirPath+filename+".jpg", options); 
int tempW = tempBitmap.getWidth(); 
int tempH = tempBitmap.getHeight(); 

if (tempW>tempH) { 
Matrix mtx = new Matrix(); 
mtx.postRotate(90); 
Bitmap rotatedBitmap = **Bitmap.createBitmap**(tempBitmap, 0,0,tempW, tempH, mtx, true); 
0

Aller par le code suivant,

Pour arrêt ratation d'utilisation d'image code suivant -

private int getImageOrientation() 
{ 
    final String[] imageColumns = {MediaStore.Images.Media._ID, MediaStore.Images.ImageColumns.ORIENTATION}; 
    final String imageOrderBy = MediaStore.Images.Media._ID + " DESC"; 
    Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 
      imageColumns, null, null, imageOrderBy); 

    if (cursor.moveToFirst()) { 
     int orientation = cursor.getInt(cursor.getColumnIndex(MediaStore.Images.ImageColumns.ORIENTATION)); 
     System.out.println("orientation===" + orientation); 
     cursor.close(); 
     return orientation; 
    } else { 
     return 0; 
    } 
} 

Si vous rencontrez un problème s'il vous plaît se référer lien suivant

http://androidlift.info/2016/01/07/android-camera-image-capturing-and-uploading-to-php-server/