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 resizeBitmap(Bitmap bm, float scale) {
    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);/*from   www . java  2 s .  c o m*/
    return Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);
}

From source file:Main.java

/**
 * Method to rotate a Bitmap specifying the angle.
 *
 * @param source The original Bitmap./*from   w ww .  j  a va  2  s  .com*/
 * @param angle  float that represents the rotation angle.
 * @return The rotated Bitmap.
 */
public static Bitmap rotate(Bitmap source, float angle) {
    Matrix matrix = new Matrix();
    matrix.postRotate(angle);
    return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}

From source file:Main.java

private static Bitmap rotateBitmap(Bitmap bmp, int degrees) {
    Matrix matrix = new Matrix();
    matrix.postRotate(degrees);/*from ww  w  .  jav a  2 s  .  c om*/

    Bitmap newBmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
    bmp.recycle();

    return newBmp;
}

From source file:Main.java

private static Bitmap trimTransparentRegions(Bitmap input, int alphaThreshold) {
    final int height = input.getHeight();
    final int width = input.getWidth();

    final int[] pixels = new int[height * width];
    input.getPixels(pixels, 0, width, 0, 0, width, height);

    int boundTop = 0, boundBottom = 0, boundLeft = 0, boundRight = 0;
    int i = 0;// ww  w. j  a  v a  2s.  co  m

    topScan: for (i = 0; i < pixels.length; i++) {
        if (isTransparent(pixels[i], alphaThreshold) == false) {
            boundTop = i / width;
            break topScan;
        }
    }

    bottomScan: for (i = pixels.length - 1; i >= 0; i--) {
        if (isTransparent(pixels[i], alphaThreshold) == false) {
            boundBottom = (pixels.length - i) / width;
            break bottomScan;
        }
    }

    /* for each x, x <- 0, scan downwards until not transparent pixel is reached */
    leftScan: for (i = 0; i < width; i++) {
        for (int j = i; j < pixels.length; j += width) {
            if (isTransparent(pixels[j], alphaThreshold) == false) {
                boundLeft = j % width;
                break leftScan;
            }
        }
    }

    /* for each x, x <- width, scan upwards until not transparent pixel is reached */
    rightScan: for (i = pixels.length - 1; i >= 0; i--) {
        for (int j = i; j >= 0; j -= width) {
            if (isTransparent(pixels[j], alphaThreshold) == false) {
                boundRight = width - (j % width);
                break rightScan;
            }
        }
    }

    return Bitmap.createBitmap(input, boundLeft, boundTop, width - boundLeft - boundRight,
            height - boundTop - boundBottom);
}

From source file:Main.java

public static Bitmap getCroppedBitmap(Bitmap bmp, int radius, int border, int color) {
    Bitmap scaledBitmap;/*from  w  w  w .j  a v a  2  s  . co  m*/
    if (bmp.getWidth() != radius || bmp.getHeight() != radius) {
        scaledBitmap = ThumbnailUtils.extractThumbnail(bmp, radius - 2, radius - 2);
    } else {
        scaledBitmap = bmp;
    }

    Bitmap output = Bitmap.createBitmap(scaledBitmap.getWidth(), scaledBitmap.getHeight(),
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawCircle(scaledBitmap.getWidth() / 2, scaledBitmap.getHeight() / 2, scaledBitmap.getWidth() / 2,
            paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    final Rect rect = new Rect(0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight());
    canvas.drawBitmap(scaledBitmap, rect, rect, paint);

    if (border > 0) {
        paint.setStrokeWidth(border);
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawCircle(scaledBitmap.getWidth() / 2, scaledBitmap.getHeight() / 2,
                scaledBitmap.getWidth() / 2, paint);
    }

    return output;
}

From source file:Main.java

public static Bitmap rotateImage(@NonNull Bitmap in, int angle) {
    Matrix mat = new Matrix();
    mat.postRotate(angle);//from  ww  w  .  j a  v  a2 s .  co m
    return Bitmap.createBitmap(in, 0, 0, in.getWidth(), in.getHeight(), mat, true);
}

From source file:Main.java

private static Bitmap processBitmap(Bitmap bm) {

    float width = bm.getWidth();
    float height = bm.getHeight();
    int maxWidth = 150;
    int maxHeight = 150;
    float oldHeight;
    int oldWidth;
    float newWidth;
    float newHeight;
    float schnitt;

    Log.i("==============>", "width: " + width);
    Log.i("==============>", "height: " + height);

    newWidth = maxWidth;//from  www  .j  av  a 2s .  c om
    schnitt = newWidth / width;
    newHeight = (int) (schnitt * height);

    if (newHeight > maxHeight) {
        oldHeight = newHeight;
        oldWidth = (int) newWidth;
        newHeight = maxHeight;
        schnitt = newHeight / oldHeight;
        newWidth = schnitt * oldWidth;
    }

    Log.i("==============>", "New Width: " + newWidth);
    Log.i("==============>", "New Height: " + newHeight);

    bm = Bitmap.createScaledBitmap(bm, (int) newWidth, (int) newHeight, true);
    Log.i(I, "create scaled Bitmap successful");

    return bm;
}

From source file:Main.java

public static Bitmap applyReflection(Bitmap originalImage) {
    final int reflectionGap = 4;
    int width = originalImage.getWidth();
    int height = originalImage.getHeight();

    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);/*from ww  w  .  ja  v a2  s.  c  om*/

    Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height / 2, width, height / 2, matrix,
            false);

    Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(originalImage, 0, 0, null);
    Paint defaultPaint = new Paint();
    canvas.drawRect(0, height, width, height + reflectionGap, defaultPaint);
    canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);

    Paint paint = new Paint();
    LinearGradient shader = new LinearGradient(0, originalImage.getHeight(), 0,
            bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, Shader.TileMode.CLAMP);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint);

    return bitmapWithReflection;
}

From source file:Main.java

/**
 * Shrinks and rotates (if necessary) a passed Bitmap.
 *
 * @param bm//from w  ww.j av a2 s . co  m
 * @param maxLengthOfEdge
 * @param rotateXDegree
 * @return Bitmap
 */
public static Bitmap shrinkBitmap(Bitmap bm, int maxLengthOfEdge, int rotateXDegree) {
    if (maxLengthOfEdge > bm.getWidth() && maxLengthOfEdge > bm.getHeight()) {
        return bm;
    } else {
        // shrink image
        float scale = (float) 1.0;
        if (bm.getHeight() > bm.getWidth()) {
            scale = ((float) maxLengthOfEdge) / bm.getHeight();
        } else {
            scale = ((float) maxLengthOfEdge) / bm.getWidth();
        }
        // CREATE CommonAsync MATRIX FOR THE MANIPULATION
        Matrix matrix = new Matrix();
        // RESIZE THE BIT MAP
        matrix.postScale(scale, scale);
        matrix.postRotate(rotateXDegree);

        // RECREATE THE NEW BITMAP
        bm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, false);

        matrix = null;
        System.gc();

        return bm;
    }
}