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 GetBitmapClippedCircle(Bitmap bitmap) {

    final int width = bitmap.getWidth();
    final int height = bitmap.getHeight();
    final Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    final Path path = new Path();
    path.addCircle((float) (width / 2), (float) (height / 2), (float) Math.min(width, (height / 2)),
            Path.Direction.CCW);/*  w ww  . j  ava 2 s.  c om*/

    final Canvas canvas = new Canvas(outputBitmap);
    canvas.clipPath(path);
    canvas.drawBitmap(bitmap, 0, 0, null);
    return outputBitmap;
}

From source file:Main.java

public static final Bitmap grey(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

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

    Canvas canvas = new Canvas(faceIconGreyBitmap);
    Paint paint = new Paint();
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0);//from w ww .  jav  a2 s  . co  m
    ColorMatrixColorFilter colorMatrixFilter = new ColorMatrixColorFilter(colorMatrix);
    paint.setColorFilter(colorMatrixFilter);
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return faceIconGreyBitmap;
}

From source file:Main.java

/** Returns a scaled version of the given Bitmap. One of the returned Bitmap's width and height will be equal to size, and the other
 * dimension will be equal or less.//from  ww  w. j  a v a2 s.c o m
 */
public static Bitmap createScaledBitmap(Bitmap bitmap, int size) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    int scaledWidth = size, scaledHeight = size;
    if (height < width) {
        scaledHeight = (int) (size * 1.0f * height / width);
    } else if (width < height) {
        scaledWidth = (int) (size * 1.0f * width / height);
    }
    Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, scaledWidth, scaledHeight, false);
    return scaledBitmap;
}

From source file:Main.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    float roundPx = w / 2;
    Bitmap output = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, w, h);
    final RectF rectF = new RectF(rect);
    paint.setAntiAlias(true);//  w w  w .  j  a  v  a2 s .  c  o  m
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}

From source file:Main.java

public static Bitmap getFullScreenBitmap(Bitmap bitmap, int wScale, int hScale) {
    int dstWidth = bitmap.getWidth() * wScale;
    int dstHeight = bitmap.getHeight() * hScale;
    Bitmap result = Bitmap.createScaledBitmap(bitmap, dstWidth, dstHeight, false);
    return result;
}

From source file:Main.java

public static Bitmap getRotatedBitmap(Bitmap mBitmap, float degrees) {
    int width = mBitmap.getWidth();
    int height = mBitmap.getHeight();

    Matrix matrix = new Matrix();
    matrix.postRotate(degrees);//from   ww w. j  av  a 2  s  .co  m
    Bitmap mRotateBitmap = Bitmap.createBitmap(mBitmap, 0, 0, width, height, matrix, true);

    return mRotateBitmap;
}

From source file:Main.java

public static Bitmap resizeBitmap(Bitmap bitmap, int maxSize) {
    int bigger = bitmap.getWidth() > bitmap.getHeight() ? bitmap.getWidth() : bitmap.getHeight();
    if (bigger > maxSize) {
        float scale = bigger / maxSize;
        return scaleBitmap(bitmap, scale);
    } else {/*from  www.  j av a2 s.c  o  m*/
        return bitmap;
    }
}

From source file:Main.java

public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) {
    int i = bitmap.getWidth();
    int j = bitmap.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1.0F, -1F);/*www. j  a  v  a2s .c  o m*/
    Bitmap bitmap1 = Bitmap.createBitmap(bitmap, 0, j / 2, i, j / 2, matrix, false);
    Bitmap bitmap2 = Bitmap.createBitmap(i, j + j / 2, android.graphics.Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap2);
    canvas.drawBitmap(bitmap, 0.0F, 0.0F, null);
    Paint paint = new Paint();
    canvas.drawRect(0.0F, j, i, j + 4, paint);
    canvas.drawBitmap(bitmap1, 0.0F, j + 4, null);
    Paint paint1 = new Paint();
    paint1.setShader(new LinearGradient(0.0F, bitmap.getHeight(), 0.0F, 4 + bitmap2.getHeight(), 0x70ffffff,
            0xffffff, android.graphics.Shader.TileMode.CLAMP));
    paint1.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DST_IN));
    canvas.drawRect(0.0F, j, i, 4 + bitmap2.getHeight(), paint1);
    return bitmap2;
}

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 scaleWidth = ((float) width / w);
    float scaleHeight = ((float) height / h);
    matrix.postScale(scaleWidth, scaleHeight);
    return Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true);
}

From source file:Main.java

@Deprecated
public static Bitmap setAlpha(Bitmap source, int number) {
    int[] argb = new int[source.getWidth() * source.getHeight()];
    source.getPixels(argb, 0, source.getWidth(), 0, 0, source.getWidth(), source.getHeight());
    number = number * 255 / 100;/*w  w w . j  a  va 2 s . com*/
    for (int i = 0; i < argb.length; i++) {
        argb[i] = (number << 24) | (argb[i] & 0x00FFFFFF);
    }
    return Bitmap.createBitmap(argb, source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
}