Kamis, 04 Oktober 2012

Create scaled bitmap using Bitmap.createScaledBitmap() method

To create a scaled bitmap from a source bitmap, we can call the static method Bitmap.createScaledBitmap().
  • public static Bitmap createScaledBitmap (Bitmap src, int dstWidth, int dstHeight, boolean filter)
    Creates a new bitmap, scaled from an existing bitmap, when possible. If the specified width and height are the same as the current width and height of the source btimap, the source bitmap is returned and now new bitmap is created.

    src: The source bitmap.
    dstWidth: The new bitmap's desired width.
    dstHeight: The new bitmap's desired height.
    filter: true if the source should be filtered.

    Returns: The new scaled bitmap or the source bitmap if no scaling is required.

Example to create scaled bitmap with 1/2 width and height:
   Bitmap scaledBitmap =  Bitmap.createScaledBitmap(
srcBitmap,
srcBitmap.getWidth()/2,
srcBitmap.getHeight()/2,
false);


0 komentar:

Posting Komentar

Copyright © 2012 Codding News All Right Reserved