diff options
author | Xavier Ducrohet <xav@android.com> | 2010-01-13 17:09:52 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2010-01-13 17:09:52 -0800 |
commit | cff6c8459ca05f3fee2d2999989d07a7176f955c (patch) | |
tree | 284d0a2d6d5f0beea96999622284840f3407364b /tools/layoutlib/bridge/src/android/graphics/Bitmap.java | |
parent | 90528645ad7d40634737075dc49a9f60bc7a1748 (diff) | |
parent | ae4bd059caa71aa4652c0f07fde7c2687169906e (diff) | |
download | frameworks_base-cff6c8459ca05f3fee2d2999989d07a7176f955c.zip frameworks_base-cff6c8459ca05f3fee2d2999989d07a7176f955c.tar.gz frameworks_base-cff6c8459ca05f3fee2d2999989d07a7176f955c.tar.bz2 |
am ae4bd059: ADT/Layoutlib: Reimplement parts of BitmapFactory
Merge commit 'ae4bd059caa71aa4652c0f07fde7c2687169906e' into eclair-plus-aosp
* commit 'ae4bd059caa71aa4652c0f07fde7c2687169906e':
ADT/Layoutlib: Reimplement parts of BitmapFactory
Diffstat (limited to 'tools/layoutlib/bridge/src/android/graphics/Bitmap.java')
-rw-r--r-- | tools/layoutlib/bridge/src/android/graphics/Bitmap.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tools/layoutlib/bridge/src/android/graphics/Bitmap.java b/tools/layoutlib/bridge/src/android/graphics/Bitmap.java index ff1b295..35f022e 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Bitmap.java +++ b/tools/layoutlib/bridge/src/android/graphics/Bitmap.java @@ -20,6 +20,7 @@ package android.graphics; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.io.InputStream; import javax.imageio.ImageIO; @@ -33,6 +34,12 @@ public final class Bitmap extends _Original_Bitmap { mImage = ImageIO.read(input); } + public Bitmap(InputStream is) throws IOException { + super(1, true, null, -1); + + mImage = ImageIO.read(is); + } + Bitmap(BufferedImage image) { super(1, true, null, -1); mImage = image; @@ -237,4 +244,35 @@ public final class Bitmap extends _Original_Bitmap { return createBitmap(colors, 0, width, width, height, config); } + public static Bitmap createScaledBitmap(Bitmap src, int dstWidth, + int dstHeight, boolean filter) { + Matrix m; + synchronized (Bitmap.class) { + // small pool of just 1 matrix + m = sScaleMatrix; + sScaleMatrix = null; + } + + if (m == null) { + m = new Matrix(); + } + + final int width = src.getWidth(); + final int height = src.getHeight(); + final float sx = dstWidth / (float)width; + final float sy = dstHeight / (float)height; + m.setScale(sx, sy); + Bitmap b = Bitmap.createBitmap(src, 0, 0, width, height, m, filter); + + synchronized (Bitmap.class) { + // do we need to check for null? why not just assign everytime? + if (sScaleMatrix == null) { + sScaleMatrix = m; + } + } + + return b; + } + + } |