Example usage for android.graphics Bitmap getWidth

List of usage examples for android.graphics Bitmap getWidth

Introduction

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

Prototype

public final int getWidth() 

Source Link

Document

Returns the bitmap's width

Usage

From source file:Main.java

public static Bitmap bigImage(Bitmap bmp, float big) {
    int bmpWidth = bmp.getWidth();
    int bmpHeight = bmp.getHeight();
    Matrix matrix = new Matrix();
    matrix.postScale(big, big);/*  www .  j a  va  2s  .c  om*/
    return Bitmap.createBitmap(bmp, 0, 0, bmpWidth, bmpHeight, matrix, true);
}

From source file:Main.java

public static Bitmap getFixedBitmap(Bitmap bm, int w, int h, boolean filter) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    Matrix matrix = new Matrix();
    matrix.postScale((float) w / width, (float) h / height);
    return Bitmap.createBitmap(bm, 0, 0, width, height, matrix, filter);
}

From source file:Main.java

public static Bitmap[] splitBitmap(Bitmap pic, int row, int col) {
    int tileWidth = pic.getWidth() / col;
    int tileHeight = pic.getHeight() / row;

    Bitmap[] tiles = new Bitmap[row * col];
    for (int r = 0; r < row; r++) {
        for (int c = 0; c < col; c++) {
            tiles[r * col + c] = Bitmap.createBitmap(pic, c * tileWidth, r * tileHeight, tileWidth, tileHeight);
        }//from w w w.ja v  a 2 s.c  om
    }
    return tiles;
}

From source file:Main.java

public static Bitmap resizeImageToHalf(Bitmap source) {
    int h = source.getHeight();
    int w = source.getWidth();
    return Bitmap.createBitmap(source, 0, 0, w, h);
}

From source file:Main.java

public static Bitmap resizeBitmap(Bitmap image, int maxSize) {
    int width = image.getWidth();
    int height = image.getHeight();
    float aspectRatio = width / (float) height;

    if (aspectRatio > 1) {
        width = maxSize;//  ww w  . j a v a  2s  .  c  o  m
        height = Math.round(width / aspectRatio);
    } else {
        height = maxSize;
        width = Math.round(height * aspectRatio);
    }

    return Bitmap.createScaledBitmap(image, width, height, true);
}

From source file:Main.java

public static boolean hasTransparentCorners(@NonNull Bitmap bitmap) {
    int right = bitmap.getWidth() - 1;
    int bottom = bitmap.getHeight() - 1;
    return bitmap.getPixel(0, 0) == Color.TRANSPARENT || bitmap.getPixel(right, 0) == Color.TRANSPARENT
            || bitmap.getPixel(0, bottom) == Color.TRANSPARENT
            || bitmap.getPixel(right, bottom) == Color.TRANSPARENT;
}

From source file:Main.java

public static Bitmap convertToAlphaMask(Bitmap b) {
    Bitmap a = Bitmap.createBitmap(b.getWidth(), b.getHeight(), Bitmap.Config.ALPHA_8);
    Canvas c = new Canvas(a);
    c.drawBitmap(b, 0.0f, 0.0f, null);//from   ww w . jav a2s  .  c  o m

    return a;
}

From source file:Main.java

public static Bitmap getOneFrameImg(Bitmap source, int frameIndex, int totalCount) {
    int singleW = source.getWidth() / totalCount;
    return Bitmap.createBitmap(source, (frameIndex - 1) * singleW, 0, singleW, source.getHeight());
}

From source file:Main.java

/**
 * center crop to target size./* w  w w  . ja v  a 2s  .c  om*/
 */
public static Bitmap centerCropBitmap(Bitmap srcBmp, int destSize) {
    int srcWidth = srcBmp.getWidth();
    int srcHeight = srcBmp.getHeight();
    if (srcWidth >= srcHeight) {
        destSize = destSize <= srcHeight ? destSize : srcHeight;
    } else {
        destSize = destSize <= srcWidth ? destSize : srcWidth;
    }
    return Bitmap.createBitmap(srcBmp, srcWidth / 2 - destSize / 2, srcHeight / 2 - destSize / 2, destSize,
            destSize);
}

From source file:Main.java

public static Bitmap zoomBitmap(Bitmap bitmap, float times) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix matrix = new Matrix();
    matrix.postScale(times, times);//from  w ww  . jav  a 2s. c  om
    Bitmap zoomBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    return zoomBitmap;
}