diff options
| author | 2011-02-16 17:57:09 -0800 | |
|---|---|---|
| committer | 2011-02-16 17:57:09 -0800 | |
| commit | 248e330092c148ff194d7742a64c1948e7d19964 (patch) | |
| tree | b825103b45ef5ba814844d3972fa54ba232a08b8 | |
| parent | 91fd9a97727b6aa0b669b92bb0f7ef1db884dd26 (diff) | |
| parent | f7f9d9c39df22ad6929f001f07588469f77e8bf5 (diff) | |
Merge "Expose an API to get a bitmap's size in bytes."
| -rw-r--r-- | api/current.xml | 11 | ||||
| -rw-r--r-- | graphics/java/android/graphics/Bitmap.java | 13 | ||||
| -rw-r--r-- | graphics/tests/graphicstests/src/android/graphics/BitmapTest.java | 6 |
3 files changed, 25 insertions, 5 deletions
diff --git a/api/current.xml b/api/current.xml index 1ce49d4d7964..71b77a6cc143 100644 --- a/api/current.xml +++ b/api/current.xml @@ -76371,6 +76371,17 @@ <parameter name="offsetXY" type="int[]"> </parameter> </method> +<method name="getByteCount" + return="int" + abstract="false" + native="false" + synchronized="false" + static="false" + final="true" + deprecated="not deprecated" + visibility="public" +> +</method> <method name="getConfig" return="android.graphics.Bitmap.Config" abstract="false" diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java index b2f4379a61d1..12dc93c3c07d 100644 --- a/graphics/java/android/graphics/Bitmap.java +++ b/graphics/java/android/graphics/Bitmap.java @@ -19,7 +19,6 @@ package android.graphics; import android.os.Parcel; import android.os.Parcelable; import android.util.DisplayMetrics; - import java.io.OutputStream; import java.nio.Buffer; import java.nio.ByteBuffer; @@ -342,7 +341,7 @@ public final class Bitmap implements Parcelable { } long bufferSize = (long)elements << shift; - long pixelSize = (long)getRowBytes() * getHeight(); + long pixelSize = getByteCount(); if (bufferSize < pixelSize) { throw new RuntimeException("Buffer not large enough for pixels"); @@ -378,7 +377,7 @@ public final class Bitmap implements Parcelable { } long bufferBytes = (long)elements << shift; - long bitmapBytes = (long)getRowBytes() * getHeight(); + long bitmapBytes = getByteCount(); if (bufferBytes < bitmapBytes) { throw new RuntimeException("Buffer not large enough for pixels"); @@ -822,6 +821,14 @@ public final class Bitmap implements Parcelable { } /** + * Returns the number of bytes used to store this bitmap's pixels. + */ + public final int getByteCount() { + // int result permits bitmaps up to 46,340 x 46,340 + return getRowBytes() * getHeight(); + } + + /** * If the bitmap's internal config is in one of the public formats, return * that config, otherwise return null. */ diff --git a/graphics/tests/graphicstests/src/android/graphics/BitmapTest.java b/graphics/tests/graphicstests/src/android/graphics/BitmapTest.java index 6734bb798c6f..685a9980fdc4 100644 --- a/graphics/tests/graphicstests/src/android/graphics/BitmapTest.java +++ b/graphics/tests/graphicstests/src/android/graphics/BitmapTest.java @@ -16,8 +16,6 @@ package android.graphics; -import android.graphics.Bitmap; -import android.graphics.Color; import android.test.suitebuilder.annotation.SmallTest; import junit.framework.TestCase; @@ -42,6 +40,10 @@ public class BitmapTest extends TestCase { assertEquals("rowbytes", 200, bm2.getRowBytes()); assertEquals("rowbytes", 200, bm3.getRowBytes()); + assertEquals("byteCount", 80000, bm1.getByteCount()); + assertEquals("byteCount", 40000, bm2.getByteCount()); + assertEquals("byteCount", 40000, bm3.getByteCount()); + assertEquals("height", 200, bm1.getHeight()); assertEquals("height", 200, bm2.getHeight()); assertEquals("height", 200, bm3.getHeight()); |