diff options
author | Jesse Wilson <jessewilson@google.com> | 2011-02-16 15:46:12 -0800 |
---|---|---|
committer | Jesse Wilson <jessewilson@google.com> | 2011-02-16 17:50:43 -0800 |
commit | f7f9d9c39df22ad6929f001f07588469f77e8bf5 (patch) | |
tree | f5b12af320df4d2b6d3c037fe1c2c40056fc200f /graphics/java | |
parent | 260a13a95edbe41fb8042b96b8c35a8a65546ec0 (diff) | |
download | frameworks_base-f7f9d9c39df22ad6929f001f07588469f77e8bf5.zip frameworks_base-f7f9d9c39df22ad6929f001f07588469f77e8bf5.tar.gz frameworks_base-f7f9d9c39df22ad6929f001f07588469f77e8bf5.tar.bz2 |
Expose an API to get a bitmap's size in bytes.
Change-Id: I960c3b02b1ba8d3a8d92aaa98955a159e6f3a228
http://b/3184897
Diffstat (limited to 'graphics/java')
-rw-r--r-- | graphics/java/android/graphics/Bitmap.java | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java index b2f4379..12dc93c 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. */ |