Example usage for android.graphics Bitmap getHeight

List of usage examples for android.graphics Bitmap getHeight

Introduction

In this page you can find the example usage for android.graphics Bitmap getHeight.

Prototype

public final int getHeight() 

Source Link

Document

Returns the bitmap's height

Usage

From source file:Main.java

public static Bitmap createWatermark(Bitmap src, Bitmap watermark, int direction, int spacing) {
    final int w = src.getWidth();
    final int h = src.getHeight();
    Bitmap bitmap = Bitmap.createBitmap(w, h, Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawBitmap(src, 0, 0, null);//  w  w  w  .  j  a va  2s  .  c  o m
    if (direction == LEFT_TOP) {
        canvas.drawBitmap(watermark, spacing, spacing, null);
    } else if (direction == LEFT_BOTTOM) {
        canvas.drawBitmap(watermark, spacing, h - watermark.getHeight() - spacing, null);
    } else if (direction == RIGHT_TOP) {
        canvas.drawBitmap(watermark, w - watermark.getWidth() - spacing, spacing, null);
    } else if (direction == RIGHT_BOTTOM) {
        canvas.drawBitmap(watermark, w - watermark.getWidth() - spacing, h - watermark.getHeight() - spacing,
                null);
    }
    return bitmap;
}

From source file:Main.java

/**
 * Method to flip vertically a Bitmap.//from   ww w.j a  v a2s  .c  om
 *
 * @param source The original Bitmap.
 * @return The flipped Bitmap.
 */
public static Bitmap flipVertically(Bitmap source) {
    Matrix m = new Matrix();
    m.preScale(1, -1);
    return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), m, false);
}

From source file:Main.java

/**
 * TODO doc//  w w  w. j  a va  2s  .  c om
 *
 * @param source
 * @return
 */
public static Bitmap flipVerticallyBitmap(Bitmap source) {
    Matrix m = new Matrix();
    m.preScale(1, -1);
    return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), m, false);
}

From source file:Main.java

public static int[] getImageSize(Context context, int drawableId) {
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), drawableId);
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    if (bitmap != null && bitmap.isRecycled()) {
        bitmap.recycle();//from  ww  w . j  a v  a 2 s. c om
    }
    int size[] = { width, height };
    return size;
}

From source file:Main.java

public static Bitmap createCroppedScaleBitmap(Bitmap src, int reqWidth, int reqHeight) {
    final int bWidth = src.getWidth();
    final int bHeight = src.getHeight();
    Matrix matrix = new Matrix();
    int maxSize = Math.max(reqHeight, reqWidth);
    float scaleX;
    if (bWidth * bHeight < reqWidth * reqHeight)
        scaleX = 0;/*from w w  w .  j a va 2  s. c o m*/
    else {
        if (bWidth > bHeight) {
            scaleX = (float) maxSize / bWidth;
        } else
            scaleX = (float) maxSize / bHeight;
    }
    Bitmap sourceBitmap;
    if (scaleX > 0 && scaleX != 1) {
        matrix.setScale(scaleX, scaleX);
        sourceBitmap = Bitmap.createBitmap(src, 0, 0, bWidth, bHeight, matrix, true);
        if (sourceBitmap != src && !src.isRecycled())
            src.recycle();
    } else
        sourceBitmap = src;
    return sourceBitmap;
}

From source file:Main.java

/**
 * Method to flip horizontally a Bitmap.
 *
 * @param source The original Bitmap./*from   www .ja v a2  s.  com*/
 * @return The flipped Bitmap.
 */
public static Bitmap flipHorizonally(Bitmap source) {
    Matrix m = new Matrix();
    m.setScale(-1, 1);
    return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), m, false);
}

From source file:Main.java

public static Bitmap createScaledBitmap(String path, float scale, boolean filtering) {
    Bitmap src = BitmapFactory.decodeFile(path);
    int width = (int) (src.getWidth() * scale + 0.5f);
    int height = (int) (src.getHeight() * scale + 0.5f);
    return Bitmap.createScaledBitmap(src, width, height, filtering);
}

From source file:Main.java

/**
 * TODO doc/*from www  . ja v a2  s.  c  om*/
 *
 * @param source
 * @return
 */
public static Bitmap flipHorizonallyBitmap(Bitmap source) {
    Matrix m = new Matrix();
    m.setScale(-1, 1);
    return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), m, false);
}

From source file:Main.java

public static Bitmap doRotate(Bitmap b, float angle) {
    Matrix matrix = new Matrix();
    matrix.postRotate(angle);/*from w  ww .jav a 2 s.c  o  m*/
    b = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), matrix, true);
    return b;
}

From source file:Main.java

public static Bitmap blurLight(Context context, Bitmap image) {
    int width = Math.round(image.getWidth() * BITMAP_SCALE_LIGHT);
    int height = Math.round(image.getHeight() * BITMAP_SCALE_LIGHT);

    Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
    Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);

    RenderScript rs = RenderScript.create(context);
    ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
    Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
    theIntrinsic.setRadius(BLUR_RADIUS_LIGHT);
    theIntrinsic.setInput(tmpIn);/*from  w w w  .  j a va  2s.co  m*/
    theIntrinsic.forEach(tmpOut);
    tmpOut.copyTo(outputBitmap);

    return outputBitmap;
}