danger.util
Class BitmapUtils

java.lang.Object
  extended by danger.util.BitmapUtils


public class BitmapUtils
extends Object

This class provides a set of static methods to manipulate Bitmaps.

Since:
4.0

Method Summary
static Bitmap tile(Bitmap src, int newWidth, int newHeight, int left, int top, int right, int bottom)
          Tile a bitmap.
static Bitmap tileHorizontal(Bitmap src, int newWidth)
          Tile a bitmap horizontally.
static Bitmap tileHorizontal(Bitmap src, int newWidth, int left, int right)
          Tile a bitmap horizontally.
static Bitmap tileVertical(Bitmap src, int newHeight)
          Tile a bitmap vertically.
static Bitmap tileVertical(Bitmap src, int newHeight, int top, int bottom)
          Tile a bitmap vertically.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

tileHorizontal

public static Bitmap tileHorizontal(Bitmap src,
                                    int newWidth)
Tile a bitmap horizontally. A new bitmap is created with the desired width. The left third of the original bitmap is copied into the leftmost portion of the new bitmap. The right third of the original bitmap is copied into the rightmost portion of the new bitmap. The rest of the new bitmap is tiled with the middle third of the original bitmap.

Parameters:
src - source bitmap.
newWidth - width of the bitmap to return.

tileHorizontal

public static Bitmap tileHorizontal(Bitmap src,
                                    int newWidth,
                                    int left,
                                    int right)

Tile a bitmap horizontally. A new bitmap is created with the desired width.

The left part of the original bitmap from x-coordinate 0 to x-coordinate left is copied into the leftmost portion of the new bitmap.

The right part of the original bitmap from x-coordinate right to the right edge is copied into the rightmost portion of the new bitmap.

The rest of the new bitmap is tiled with the middle section of the original bitmap.

Note that calling tileHorizontal(newWidth, 0, getWidth()) results in tiling the entire image.

Parameters:
src - source bitmap.
newWidth - new width of the bitmap.
left - right edge of left portion to copy.
right - left edge of right portion to copy.
Since:
4.0

tileVertical

public static Bitmap tileVertical(Bitmap src,
                                  int newHeight)
Tile a bitmap vertically. A new bitmap is created with the desired height. The top third of the original bitmap is copied into the topmost portion of the new bitmap. The bottom third of the original bitmap is copied into the bottommost portion of the new bitmap. The rest of the new bitmap is tiled with the middle third of the original bitmap.

Parameters:
src - source bitmap.
newHeight - height of the bitmap to return.

tileVertical

public static Bitmap tileVertical(Bitmap src,
                                  int newHeight,
                                  int top,
                                  int bottom)

Tile a bitmap vertically. A new bitmap is created with the desired height.

The top part of the original bitmap from y-coordinate 0 to y-coordinate top is copied into the topmost portion of the new bitmap.

The bottom part of the original bitmap from y-coordinate bottom to the bottom edge is copied into the bottommost portion of the new bitmap.

The rest of the new bitmap is tiled with the middle section of the original bitmap.

Note that calling tileVertical(newHeight, 0, getHeight()) results in tiling the entire image.

Parameters:
src - source bitmap.
newHeight - new height of the bitmap.
top - bottom edge of top portion to copy.
bottom - top edge of bottom portion to copy.

tile

public static Bitmap tile(Bitmap src,
                          int newWidth,
                          int newHeight,
                          int left,
                          int top,
                          int right,
                          int bottom)
Tile a bitmap. Note that this is different than scaling. Basically, the image is divided into 9 sections, and the sections are tiled (not scaled) as necessary in the new bitmap. A new bitmap is created with the desired width and height. The 4 corner sections are copied. The 4 edge sections are tiled appropriately, and the middle section is tiled in the center.

Parameters:
src - source bitmap.
newWidth - new width of the bitmap.
newHeight - new height of the bitmap.
left - right edge of left 3 sections to copy.
top - bottom edge of top 3 sections to copy.
right - left edge of right 3 sections to copy.
bottom - top edge of bottom 3 sections to copy.