summaryrefslogtreecommitdiffstats
path: root/graphics/java/android
diff options
context:
space:
mode:
authorAndroid (Google) Code Review <android-gerrit@google.com>2009-07-19 21:14:48 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2009-07-19 21:14:48 -0700
commitbec99bffeecacb1af603966391014895f9a16025 (patch)
tree698db3ee01626f7e4f8db3ba3dce56f44aa45d74 /graphics/java/android
parent79b7c68d5a1979a67d1d5ec6b9229aaab79cad3e (diff)
parent5c536e9162721c460699a041959a0d67de1d20db (diff)
downloadframeworks_base-bec99bffeecacb1af603966391014895f9a16025.zip
frameworks_base-bec99bffeecacb1af603966391014895f9a16025.tar.gz
frameworks_base-bec99bffeecacb1af603966391014895f9a16025.tar.bz2
am 5c536e91: Merge change 7840 into donut
Merge commit '5c536e9162721c460699a041959a0d67de1d20db' * commit '5c536e9162721c460699a041959a0d67de1d20db': Fix issue where scaled bitmap sizes could be wrong.
Diffstat (limited to 'graphics/java/android')
-rw-r--r--graphics/java/android/graphics/Bitmap.java47
1 files changed, 43 insertions, 4 deletions
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java
index 141553e..df659ef 100644
--- a/graphics/java/android/graphics/Bitmap.java
+++ b/graphics/java/android/graphics/Bitmap.java
@@ -18,6 +18,7 @@ package android.graphics;
import android.os.Parcel;
import android.os.Parcelable;
+import android.util.DisplayMetrics;
import java.io.OutputStream;
import java.nio.Buffer;
@@ -605,22 +606,60 @@ public final class Bitmap implements Parcelable {
* Convenience method that returns the width of this bitmap divided
* by the density scale factor.
*
+ * @param canvas The Canvas the bitmap will be drawn to.
* @return The scaled width of this bitmap, according to the density scale factor.
*/
- public int getScaledWidth() {
+ public int getScaledWidth(Canvas canvas) {
final float scale = mDensityScale;
- return scale == DENSITY_SCALE_UNKNOWN ? getWidth() : (int) (getWidth() / scale);
+ if (!mAutoScaling || scale < 0) {
+ return getWidth();
+ }
+ return (int)(getWidth() * canvas.getDensityScale() / scale);
+ }
+
+ /**
+ * Convenience method that returns the height of this bitmap divided
+ * by the density scale factor.
+ *
+ * @param canvas The Canvas the bitmap will be drawn to.
+ * @return The scaled height of this bitmap, according to the density scale factor.
+ */
+ public int getScaledHeight(Canvas canvas) {
+ final float scale = mDensityScale;
+ if (!mAutoScaling || scale < 0) {
+ return getHeight();
+ }
+ return (int)(getHeight() * canvas.getDensityScale() / scale);
+ }
+
+ /**
+ * Convenience method that returns the width of this bitmap divided
+ * by the density scale factor.
+ *
+ * @param metrics The target display metrics.
+ * @return The scaled width of this bitmap, according to the density scale factor.
+ */
+ public int getScaledWidth(DisplayMetrics metrics) {
+ final float scale = mDensityScale;
+ if (!mAutoScaling || scale < 0) {
+ return getWidth();
+ }
+ return (int)(getWidth() * metrics.density / scale);
}
/**
* Convenience method that returns the height of this bitmap divided
* by the density scale factor.
*
+ * @param metrics The target display metrics.
* @return The scaled height of this bitmap, according to the density scale factor.
*/
- public int getScaledHeight() {
+ public int getScaledHeight(DisplayMetrics metrics) {
final float scale = mDensityScale;
- return scale == DENSITY_SCALE_UNKNOWN ? getWidth() : (int) (getHeight() / scale);
+ if (!mAutoScaling || scale < 0) {
+ return getHeight();
+ }
+ return (int)(getHeight() * metrics.density / scale);
}
/**