Here you can find the source of generateScaledBitmap(byte[] bitMapData, int width, int height)
Parameter | Description |
---|---|
bitMapData | a byte array representation of an image to be scaled |
width | the new Bitmap's desired width |
height | the new Bitmap's desired height |
public static Bitmap generateScaledBitmap(byte[] bitMapData, int width, int height)
//package com.java2s; //License from project: Apache License import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; public class Main { /**/* w ww. ja va 2 s . c o m*/ * Generates a bitmap scaled to provided width and height * * @param drawable a valid BitmapDrawable to be scaled * @param width the new Bitmap's desired width * @param height the new Bitmap's desired height * @return A Bitmap scaled to the provided height and width */ public static Bitmap generateScaledBitmap(Drawable drawable, int width, int height) { if (drawable != null && drawable instanceof BitmapDrawable) { Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); return generateScaledBitmap(bitmap, width, height); } else { return null; } } /** * Generates a bitmap scaled to provided width and height * * @param bitmap a Bitmap to be scaled * @param width the new Bitmap's desired width * @param height the new Bitmap's desired height * @return A Bitmap scaled to the provided height and width */ public static Bitmap generateScaledBitmap(Bitmap bitmap, int width, int height) { if (bitmap != null) { try { return Bitmap.createScaledBitmap(bitmap, width, height, true); } catch (IllegalArgumentException illegalArgs) { return null; } } else { return null; } } /** * Generates a bitmap scaled to provided width and height * * @param bitMapData a byte array representation of an image to be scaled * @param width the new Bitmap's desired width * @param height the new Bitmap's desired height * @return A Bitmap scaled to the provided height and width */ public static Bitmap generateScaledBitmap(byte[] bitMapData, int width, int height) { if (bitMapData != null) { try { Bitmap bitmap = BitmapFactory.decodeByteArray(bitMapData, 0, bitMapData.length); return generateScaledBitmap(bitmap, width, height); } catch (ArrayIndexOutOfBoundsException indexOutOfBounds) { return null; } catch (IllegalArgumentException illegalArgs) { return null; } } else { return null; } } }