Skip to content

Commit

Permalink
修改图片太大时会旋转的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
chengzichen committed Jul 8, 2017
1 parent 60b775f commit 12ba485
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
14 changes: 5 additions & 9 deletions gallery/src/main/java/com/dhc/gallery/proxy/PhotoViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int count = getChildCount();

int paddingBottom = 0;
int paddingBottom = 0;

for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
Expand Down Expand Up @@ -568,7 +567,7 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin;
break;
case Gravity.RIGHT:
childLeft = r - width - lp.rightMargin;
childLeft = (r - l - width) - lp.rightMargin;
break;
case Gravity.LEFT:
default:
Expand All @@ -580,8 +579,7 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
childTop = lp.topMargin;
break;
case Gravity.CENTER_VERTICAL:
childTop = ((b - paddingBottom) - t - height) / 2 + lp.topMargin
- lp.bottomMargin;
childTop = ((b - paddingBottom) - t - height) / 2 + lp.topMargin - lp.bottomMargin;
break;
case Gravity.BOTTOM:
childTop = ((b - paddingBottom) - t) - height - lp.bottomMargin;
Expand Down Expand Up @@ -2060,14 +2058,12 @@ public void closePhoto(boolean animated, boolean fromEditMode) {
animatingImageView.setLayoutParams(layoutParams);

float scaleX = (float) AndroidUtilities.displaySize.x / layoutParams.width;
float scaleY = (float) (AndroidUtilities.displaySize.y
- AndroidUtilities.statusBarHeight) / layoutParams.height;
float scaleY = (float) (AndroidUtilities.displaySize.y + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)) / layoutParams.height;
float scale2 = scaleX > scaleY ? scaleY : scaleX;
float width = layoutParams.width * scale * scale2;
float height = layoutParams.height * scale * scale2;
float xPos = (AndroidUtilities.displaySize.x - width) / 2.0f;
float yPos = (AndroidUtilities.displaySize.y - AndroidUtilities.statusBarHeight
- height) / 2.0f;
float yPos = ((AndroidUtilities.displaySize.y + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)) - height) / 2.0f;
animatingImageView.setTranslationX(xPos + translationX);
animatingImageView.setTranslationY(yPos + translationY);
animatingImageView.setScaleX(scale * scale2);
Expand Down
20 changes: 20 additions & 0 deletions gallery/src/main/java/com/dhc/gallery/ui/CameraActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.hardware.Camera;
import android.media.ExifInterface;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.MotionEvent;
Expand All @@ -40,6 +42,7 @@
import java.io.File;
import java.util.ArrayList;

import static android.content.ContentValues.TAG;
import static com.dhc.gallery.ui.GalleryActivity.GALLERY_CONFIG;

/**
Expand Down Expand Up @@ -350,6 +353,23 @@ public void run() {
PhotoViewer.getInstance().setParentActivity(CameraActivity.this.getParentActivity());
cameraPhoto = new ArrayList<>();
int orientation = 0;
try {
ExifInterface ei = new ExifInterface(cameraFile.getAbsolutePath());
int exif = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (exif) {
case ExifInterface.ORIENTATION_ROTATE_90:
orientation = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
orientation = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
orientation = 270;
break;
}
} catch (Exception e) {
Log.d(TAG, "run "+e);
}
cameraPhoto.add(new MediaController.PhotoEntry(0, 0, 0, cameraFile.getAbsolutePath(), orientation, false));
PhotoViewer.getInstance().openPhotoForSelect(cameraPhoto, false, 0, 1,
new PhotoViewer.EmptyPhotoViewerProvider() {
Expand Down

0 comments on commit 12ba485

Please sign in to comment.