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 greyScale(Bitmap source) {
    int width = source.getWidth();
    int height = source.getHeight();

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    ColorMatrix saturation = new ColorMatrix();
    saturation.setSaturation(0f);/*from  ww w  .  j a  v a 2  s  . co  m*/
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(saturation));
    canvas.drawBitmap(source, 0, 0, paint);
    source.recycle();

    if (source != bitmap) {
        source.recycle();
    }

    return bitmap;
}

From source file:Main.java

public static Bitmap cropSquareBitmap(Bitmap srcBmp) {
    Bitmap dstBmp;//w  w w .  ja v a 2  s .c  o m
    if (srcBmp.getWidth() >= srcBmp.getHeight()) {

        dstBmp = Bitmap.createBitmap(srcBmp, srcBmp.getWidth() / 2 - srcBmp.getHeight() / 2, 0,
                srcBmp.getHeight(), srcBmp.getHeight());

    } else {

        dstBmp = Bitmap.createBitmap(srcBmp, 0, srcBmp.getHeight() / 2 - srcBmp.getWidth() / 2,
                srcBmp.getWidth(), srcBmp.getWidth());
    }

    return dstBmp;
}

From source file:Main.java

public static Bitmap createBitmap(Bitmap bitmap, final String s) {
    bitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    bitmap.eraseColor(Color.parseColor(s));
    return bitmap;
}

From source file:Main.java

public static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;
    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
    return resizedBitmap;
}

From source file:Main.java

/**
 * Get the hashcode for a bitmap.//from  w  w w  .j a  v a  2s  .com
 */
private static String hashBitmap(Bitmap bmp) {
    int[] allpixels = new int[bmp.getHeight() * bmp.getWidth()];
    bmp.getPixels(allpixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());
    return Integer.toHexString(Arrays.hashCode(allpixels));
}

From source file:Main.java

public static boolean checkBitmap(Bitmap bitmap) {
    if (null == bitmap || bitmap.isRecycled() || bitmap.getWidth() <= 0 || bitmap.getHeight() <= 0) {
        return false;
    }//from w  w  w .  j a  va2 s.c  om
    return true;
}

From source file:Main.java

public static Bitmap scaleBitmap(Bitmap source, int targetSize) {
    int sourceW = source.getWidth();
    int sourceH = source.getHeight();

    float scaleFactor = (float) Math.sqrt(source.getByteCount() / targetSize);

    int dstWidth = (int) (sourceW / scaleFactor);
    int dstHeight = (int) (sourceH / scaleFactor);

    Bitmap scaledBitmap = createScaledBitmap(source, dstWidth, dstHeight, true);
    return scaledBitmap;
}

From source file:Main.java

public static boolean isEmpty(Bitmap image) {
    return image == null || image == EMPTY_BITMAP || (image.getWidth() == 1 && image.getHeight() == 1);
}

From source file:Main.java

public static Bitmap makeCircleBitmap(Bitmap original) {
    final int width = original.getWidth();
    final int height = original.getHeight();
    final float radius = Math.min(width, height) / 2;

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Paint paint = new Paint();
    paint.setAntiAlias(true);//from w ww  .  j a  v a  2  s.  co  m
    paint.setShader(new BitmapShader(original, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));

    Canvas canvas = new Canvas(bitmap);
    canvas.drawCircle(radius, radius, radius, paint);

    original.recycle();
    return bitmap;
}

From source file:Main.java

public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix matrix = new Matrix();
    float x = (float) w / width;
    float y = (float) h / height;
    matrix.postScale(x, y);/* w  w  w.ja  va  2 s.  c  o m*/
    Bitmap zoomBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    return zoomBitmap;
}