Example usage for android.graphics Bitmap getHeight

List of usage examples for android.graphics Bitmap getHeight

Introduction

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

Prototype

public final int getHeight() 

Source Link

Document

Returns the bitmap's height

Usage

From source file:Main.java

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

    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);//  w ww.  ja v  a 2 s .  co m

    Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height / 2, width, height / 2, matrix, false);

    Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(bitmap, 0, 0, null);
    Paint deafalutPaint = new Paint();
    canvas.drawRect(0, height, width, height + reflectionGap, deafalutPaint);

    canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);

    Paint paint = new Paint();
    LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0,
            bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP);
    paint.setShader(shader);
    // Set the Transfer mode to be porter duff and destination in
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    // Draw a rectangle using the paint with our linear gradient
    canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint);

    return bitmapWithReflection;
}

From source file:Main.java

public static Bitmap scaleBitmap(Bitmap bitmap, int reW, int reH) {
    if (bitmap == null) {
        return null;
    }/* w  w w  . j  a v  a2s . c om*/
    int bmpW = bitmap.getWidth();
    int bmpH = bitmap.getHeight();
    float wScale = reW * 1.0f / bmpW;
    float hScale = reH * 1.0f / bmpH;
    float scale = Math.max(wScale, hScale);
    Matrix matrix = new Matrix();
    matrix.setScale(scale, scale);
    return Bitmap.createBitmap(bitmap, 0, 0, bmpW, bmpH, matrix, true);
}

From source file:Main.java

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

    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);//from w  w w .  j a v a 2 s  .c om

    Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height / 2, width, height / 2, matrix, false);

    Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(bitmap, 0, 0, null);
    Paint deafalutPaint = new Paint();
    canvas.drawRect(0, height, width, height + reflectionGap, deafalutPaint);

    canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);

    Paint paint = new Paint();
    LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0,
            bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP);
    paint.setShader(shader);
    // Set the Transfer mode to be porter duff and destination in
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    // Draw a rectangle using the paint with our linear gradient
    canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint);

    return bitmapWithReflection;
}

From source file:Main.java

public static Point getImageDimension(Context context, int resource) {
    Bitmap bm = BitmapFactory.decodeResource(context.getResources(), resource);
    Point point = new Point();
    point.x = bm.getWidth();//  w  w  w . j  a va 2s  .  c om
    point.y = bm.getHeight();
    bm.recycle();
    bm = null;

    return point;
}

From source file:Main.java

/**
 * Create rounded corner bitmap.//from   w w w.  java 2 s .co  m
 *
 * @param bitmap bitmap.
 * @return rounded bitmap.
 */
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    Bitmap source = Bitmap.createScaledBitmap(bitmap, 480, 480, false);
    Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), 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, source.getWidth(), source.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = source.getWidth();

    paint.setAntiAlias(true);
    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(source, rect, rect, paint);

    return output;
}

From source file:Main.java

public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h) {
    Bitmap newbmp = null;// w  w  w .  j  a v a  2 s. co  m
    if (bitmap != null) {
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        Matrix matrix = new Matrix();
        float scaleWidht = ((float) w / width);
        float scaleHeight = ((float) h / height);
        matrix.postScale(scaleWidht, scaleHeight);
        newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    }
    return newbmp;
}

From source file:Main.java

public static Bitmap rotate(Bitmap originalBitmap, float alpha) {
    if (originalBitmap == null)
        return null;
    int width = originalBitmap.getWidth();
    int height = originalBitmap.getHeight();
    Matrix matrix = new Matrix();
    matrix.setRotate(alpha);//from w w w .  ja  v  a2s .co  m
    return Bitmap.createBitmap(originalBitmap, 0, 0, width, height, matrix, true);
}

From source file:Main.java

public static Bitmap int2Icon(Context context, int i) {
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), 0x7f020047);
    Bitmap bitmap1 = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(),
            android.graphics.Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap1);
    Paint paint = new Paint();
    paint.setDither(true);/*  ww w.jav a  2  s  .  c o m*/
    paint.setFilterBitmap(true);
    canvas.drawBitmap(bitmap, 0.0F, 0.0F, paint);
    bitmap.recycle();
    Paint paint1 = new Paint(257);
    paint1.setColor(-1);
    paint1.setTypeface(Typeface.DEFAULT_BOLD);
    paint1.setTextAlign(android.graphics.Paint.Align.CENTER);
    canvas.drawText(String.valueOf(i), bitmap.getWidth() / 2, 3 + bitmap.getHeight() / 2, paint1);
    return bitmap1;
}

From source file:Main.java

private static Bitmap rotaingImageView(int angle, Bitmap bitmap) {
    Matrix matrix = new Matrix();
    matrix.postRotate(angle);/* ww w.  j  a  v  a  2  s.c  om*/
    Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix,
            true);
    return resizedBitmap;
}

From source file:Main.java

public static Bitmap zoomBitmap(float scale, Bitmap bitmap) {
    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);/*w w w .j  ava  2  s  . com*/
    Bitmap newBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    return newBitmap;
}