Merge "Fix crash when creating a HW Bitmap on a detached view" into oc-mr1-dev
This commit is contained in:
@@ -159,11 +159,14 @@ public class TransitionUtils {
|
|||||||
* @return A bitmap of the given view or null if bounds has no width or height.
|
* @return A bitmap of the given view or null if bounds has no width or height.
|
||||||
*/
|
*/
|
||||||
public static Bitmap createViewBitmap(View view, Matrix matrix, RectF bounds) {
|
public static Bitmap createViewBitmap(View view, Matrix matrix, RectF bounds) {
|
||||||
|
if (!view.isAttachedToWindow()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
Bitmap bitmap = null;
|
Bitmap bitmap = null;
|
||||||
int bitmapWidth = Math.round(bounds.width());
|
int bitmapWidth = Math.round(bounds.width());
|
||||||
int bitmapHeight = Math.round(bounds.height());
|
int bitmapHeight = Math.round(bounds.height());
|
||||||
if (bitmapWidth > 0 && bitmapHeight > 0) {
|
if (bitmapWidth > 0 && bitmapHeight > 0) {
|
||||||
float scale = Math.min(1f, ((float)MAX_IMAGE_SIZE) / (bitmapWidth * bitmapHeight));
|
float scale = Math.min(1f, ((float) MAX_IMAGE_SIZE) / (bitmapWidth * bitmapHeight));
|
||||||
bitmapWidth *= scale;
|
bitmapWidth *= scale;
|
||||||
bitmapHeight *= scale;
|
bitmapHeight *= scale;
|
||||||
matrix.postTranslate(-bounds.left, -bounds.top);
|
matrix.postTranslate(-bounds.left, -bounds.top);
|
||||||
|
|||||||
Reference in New Issue
Block a user