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 scaleBitmapWidth(Bitmap bitmap, int width) {
    float ratio = bitmap.getWidth() / bitmap.getHeight();
    return scaleBitmap(bitmap, width, (width * bitmap.getHeight()) / bitmap.getWidth());
}

From source file:Main.java

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

From source file:Main.java

public static Bitmap zoomBitmap(Bitmap bitmap, float scale) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Log.e("ss", "width=" + width);
    Log.e("ss", "height=" + height);
    Matrix matrix = new Matrix();
    //float scaleWidht = ((float)w / width);
    //float scaleHeight = ((float)h / height);
    matrix.postScale(scale, scale);//w ww  . j  a v a2  s .  c om
    Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    return newbmp;
}

From source file:Main.java

public static Bitmap scaleBitmap(int maxWidth, int maxHeight, Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    float scale = 1;

    if (height > width) {
        if (height > maxHeight) {
            scale = (float) maxHeight / (float) height;
        }//from ww w.j  ava  2  s.c o m
    } else {
        if (width > maxWidth) {
            scale = (float) maxWidth / (float) width;
        }
    }

    width = (int) (width * scale);
    height = (int) (height * scale);

    return Bitmap.createScaledBitmap(bitmap, width, height, false);
}

From source file:Main.java

public static Bitmap PicZoom(Bitmap bmp, int width, int height) {
    int bmpWidth = bmp.getWidth();
    int bmpHeght = bmp.getHeight();
    Matrix matrix = new Matrix();
    matrix.postScale((float) width / bmpWidth, (float) height / bmpHeght);
    return Bitmap.createBitmap(bmp, 0, 0, bmpWidth, bmpHeght, matrix, true);
}

From source file:Main.java

public static Bitmap convertGrayscale(final Bitmap source) {
    final int width = source.getWidth();
    final int height = source.getHeight();
    final Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);
    final Paint paint = new Paint();
    final ColorMatrix matrix = new ColorMatrix();
    matrix.setSaturation(0f);//  w  ww . ja  v  a  2s .  co m
    paint.setColorFilter(new ColorMatrixColorFilter(matrix));
    canvas.drawBitmap(source, 0, 0, paint);
    return output;
}

From source file:Main.java

public static Bitmap scaleBitmapHeight(Bitmap bitmap, int height) {
    float ratio = bitmap.getWidth() / bitmap.getHeight();
    return scaleBitmap(bitmap, height, (height * bitmap.getWidth()) / bitmap.getHeight());
}

From source file:Main.java

public static Bitmap scaleBitmap(Bitmap srcBitmap, int newSize) {
    int w = srcBitmap.getWidth();
    int h = srcBitmap.getHeight();

    // Determine the scaling required to get desired result.
    float scaleW = newSize / (float) w;
    float scaleH = newSize / (float) h;

    Matrix matrix = new Matrix();
    matrix.postScale(scaleW, scaleH);//from w  ww. j ava 2  s .  co m

    return Bitmap.createBitmap(srcBitmap, 0, 0, w, h, matrix, false);
}

From source file:Main.java

static public Bitmap scaleBitmapToPx(Context context, Bitmap bitmap, float dpX, float dpY) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    return scaleBitmap(bitmap, dpX / width, dpY / height);
}

From source file:Main.java

public static Bitmap resizeBitmap(Bitmap bm, int w, int h) {
    Bitmap BitmapOrg = bm;

    int width = BitmapOrg.getWidth();
    int height = BitmapOrg.getHeight();

    float scaleWidth = ((float) w) / width;
    float scaleHeight = ((float) h) / height;

    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    return Bitmap.createBitmap(BitmapOrg, 0, 0, width, height, matrix, true);
}