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

static public Bitmap scaleToFitWidth(Bitmap b, int width) {
    float factor = width / (float) b.getWidth();
    return Bitmap.createScaledBitmap(b, width, (int) (b.getHeight() * factor), true);
}

From source file:Main.java

public static final Bitmap grey(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap greyBitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Canvas canvas = new Canvas(greyBitmap);
    Paint paint = new Paint();
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0);//from  ww w.j  a v  a  2 s.c om
    ColorMatrixColorFilter colorMatrixFilter = new ColorMatrixColorFilter(colorMatrix);
    paint.setColorFilter(colorMatrixFilter);
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return greyBitmap;
}

From source file:Main.java

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

From source file:Main.java

public static int getProportionFullWidthHeight(int screenWidth, Bitmap bitmap, Context context) {
    double width = bitmap.getWidth();
    double height = bitmap.getHeight();
    double proportion = screenWidth / width;
    double proportionHeight = height * proportion;
    return (int) proportionHeight;
}

From source file:Main.java

/**
 * reversal bitmap at left-right//  w w w.  j a va 2s . c  o  m
 * 
 * @param originalImage
 * @return the bitmap after reversal
 */
public static Bitmap createReversal(Bitmap originalImage) {
    int width = originalImage.getWidth();
    int height = originalImage.getHeight();

    Matrix matrix = new Matrix();
    matrix.preScale(-1.0f, 1.0f);

    return Bitmap.createBitmap(originalImage, 0, 0, width, height, matrix, false);
}

From source file:Main.java

public static Bitmap scaleBitmapByFactor(Bitmap source, float factor) {
    int newWidth = (int) (source.getWidth() * factor);
    int newHeight = (int) (source.getHeight() * factor);
    return Bitmap.createScaledBitmap(source, newWidth, newHeight, true);
}

From source file:Main.java

public static Bitmap zoom(Bitmap bitmap, int w, int h) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix matrix = new Matrix();
    float scaleWidth = ((float) w / width);
    float scaleHeight = ((float) h / height);
    matrix.postScale(scaleWidth, scaleHeight);
    return Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
}

From source file:Main.java

public static Bitmap resizeBitmapToFitWidth(Bitmap bm, int width) {
    int oriWidth = bm.getWidth();
    int oriHeight = bm.getHeight();
    if (oriWidth < width) {
        return bm;
    } else {//from ww w .j a  v a 2s .com
        int height = (int) ((float) width / oriWidth * oriHeight);
        Bitmap tmp = Bitmap.createScaledBitmap(bm, width, height, false);
        bm.recycle();
        return tmp;
    }
}

From source file:Main.java

public static Bitmap resizeBitmap(Bitmap bitmap, int w, int h) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    float scaleWidth = ((float) w) / width;
    float scaleHeight = ((float) h) / height;
    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    return Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
}

From source file:Main.java

public static Bitmap zoomBitmap3(Bitmap bitmap, int w, int h) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix matrix = new Matrix();
    float ratio = ((float) w / width);

    matrix.postScale(ratio, ratio);//from   w w w  .j  a  v a 2 s.  c  o m
    Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    return newbmp;
}