android-slideshow icon indicating copy to clipboard operation
android-slideshow copied to clipboard

Issue with Exif tags, glide strategy and Auto

Open mettyw opened this issue 6 years ago • 2 comments

It seems to me that AUTO_ROTATE_DIMEN only works if device in portrait mode. My understanding would be, that when this option is selected, the image always fills the maximum amount of screen space, no matter in what orientation the device currently is?

Based on that I have the following suggestions:

  1. I think within GlideRotateDimenTransformation there must be another if statement checking whether toTransform.getHeight() >= toTransform.getWidth() and both cases must be handled separately.

  2. Related to the above, I sometimes saw weird orientations of images when rotating the device during slideshow display. I think GlideRotateDimenTransformation.getID() then must be "more" unique because the Id is used for caching according to the Javadoc. If it is cached, the transform(..) method will not be called again and the need for transformation will not be calculated again based on the current rotation.

mettyw avatar Jan 13 '19 16:01 mettyw

The following code seems to fix the issues I had, but I am not sure whether this is a proper fix, especially the Math.random() part in getId() ...

@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
	Log.d(TAG, String.format("Height: %d Width: %d", toTransform.getHeight(), toTransform.getWidth()));
	if ( outWidth <= outHeight) {
		if (toTransform.getHeight() >= toTransform.getWidth()){
			// Perform fit center here on un-rotated image.
			toTransform = TransformationUtils.fitCenter(toTransform, pool, outWidth, outHeight);
			return toTransform;
		} else {
			// Fit center using largest side (width) for both to reduce computation for rotate
			//noinspection SuspiciousNameCombination
			toTransform = TransformationUtils.fitCenter(toTransform, pool, outWidth, outWidth);
			return TransformationUtils.rotateImage(toTransform, 90);
		}
	}
	else {
		// note: width and height are switched in this if statement
		if (toTransform.getWidth() >= toTransform.getHeight()){
			// Perform fit center here on un-rotated image.
			toTransform = TransformationUtils.fitCenter(toTransform, pool, outWidth, outHeight);
			return toTransform;
		} else {
			// Fit center using largest side (height) for both to reduce computation for rotate
			//noinspection SuspiciousNameCombination
			toTransform = TransformationUtils.fitCenter(toTransform, pool, outHeight, outHeight);
			return TransformationUtils.rotateImage(toTransform, 90);
		}
	}
}

@Override
public String getId() {
	return TAG + Math.random(); //FIXME
}

mettyw avatar Jan 13 '19 16:01 mettyw

Optimised:

@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
	Log.d(TAG, String.format("Height: %d Width: %d", toTransform.getHeight(), toTransform.getWidth()));
	boolean largerHeight = outHeight > outWidth;
	if ((largerHeight && toTransform.getHeight() >= toTransform.getWidth()) ||
			(!largerHeight && toTransform.getWidth() >= toTransform.getHeight())){
		// Perform fit center here on un-rotated image.
		toTransform = TransformationUtils.fitCenter(toTransform, pool, outWidth, outHeight);
		return toTransform;
	} else {
		int largest = largerHeight ? outHeight : outWidth;
		// Fit center using largest side for both to reduce computation for rotate
		//noinspection SuspiciousNameCombination
		toTransform = TransformationUtils.fitCenter(toTransform, pool, largest, largest);
		return TransformationUtils.rotateImage(toTransform, 90);
	}
}

The Id just has to be unique, so Math.random is fine.

This seems like a good approach, so let's go with it.

ScreamingHawk avatar Jan 13 '19 19:01 ScreamingHawk