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 boost(Bitmap src, int type, float percent) {
    int width = src.getWidth();
    int height = src.getHeight();
    Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());

    int A, R, G, B;
    int pixel;/*from  w w w .j  a v a  2 s.  co m*/

    for (int x = 0; x < width; ++x) {
        for (int y = 0; y < height; ++y) {
            pixel = src.getPixel(x, y);
            A = Color.alpha(pixel);
            R = Color.red(pixel);
            G = Color.green(pixel);
            B = Color.blue(pixel);
            if (type == 1) {
                R = (int) (R * (1 + percent));
                if (R > 255)
                    R = 255;
            } else if (type == 2) {
                G = (int) (G * (1 + percent));
                if (G > 255)
                    G = 255;
            } else if (type == 3) {
                B = (int) (B * (1 + percent));
                if (B > 255)
                    B = 255;
            }
            bmOut.setPixel(x, y, Color.argb(A, R, G, B));
        }
    }
    return bmOut;
}

From source file:Main.java

public static Bitmap getCroppedBitmap(Bitmap bmp, int radius) {
    Bitmap sbmp;/*from  ww w .  j  av  a2 s . c  om*/

    if (bmp.getWidth() != radius || bmp.getHeight() != radius)
        sbmp = Bitmap.createScaledBitmap(bmp, radius, radius, false);
    else
        sbmp = bmp;

    Bitmap output = Bitmap.createBitmap(sbmp.getWidth(), sbmp.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    //final int color = 0xffa19774;
    final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    final Rect rect = new Rect(0, 0, sbmp.getWidth(), sbmp.getHeight());

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);

    canvas.drawARGB(0, 0, 0, 0);

    paint.setColor(Color.parseColor("#BAB399"));

    canvas.drawCircle(sbmp.getWidth() / 2 + 0.7f, sbmp.getHeight() / 2 + 0.7f, sbmp.getWidth() / 2 + 0.1f,
            paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));

    canvas.drawBitmap(sbmp, rect, rect, paint);

    return output;
}

From source file:Main.java

public static Bitmap scaleBitmap(Bitmap originalBitmap, int toWidth, int toHeight) {

    int image_width = originalBitmap.getWidth();
    int image_height = originalBitmap.getHeight();

    float scale = (float) toWidth / (float) image_width;

    if (image_width < image_height) {
        scale = toHeight / image_height;
    }//from w  w  w.  j  a  va 2 s. c o m

    return Bitmap.createScaledBitmap(originalBitmap, (int) (image_width * scale), (int) (image_height * scale),
            true);

}

From source file:Main.java

public static Bitmap scale(Bitmap bm, double widthScale, double heightScale) {
    return Bitmap.createScaledBitmap(bm, (int) (bm.getWidth() * widthScale),
            (int) (bm.getHeight() * heightScale), false);
}

From source file:Main.java

public static Bitmap resizeBitmap(Bitmap input, int destWidth, int destHeight) {
    int srcWidth = input.getWidth();
    int srcHeight = input.getHeight();
    boolean needsResize = false;
    float p;/*from  w  w  w.j  a  va  2  s.c o  m*/
    if (srcWidth > destWidth || srcHeight > destHeight) {
        needsResize = true;
        if (srcWidth > srcHeight && srcWidth > destWidth) {
            p = (float) destWidth / (float) srcWidth;
            destHeight = (int) (srcHeight * p);
        } else {
            p = (float) destHeight / (float) srcHeight;
            destWidth = (int) (srcWidth * p);
        }
    } else {
        destWidth = srcWidth;
        destHeight = srcHeight;
    }
    if (needsResize) {
        Bitmap output = Bitmap.createScaledBitmap(input, destWidth, destHeight, true);
        return output;
    } else {
        return input;
    }
}

From source file:Main.java

public static Bitmap getSolideSizeBitmap(Bitmap bm, int width, int height) {
    float widthScale = (width * 1f) / (bm.getWidth() * 1f);
    float heightScale = (height * 1f) / (bm.getHeight() * 1f);
    Matrix matrix = new Matrix();
    matrix.setScale(widthScale, heightScale);
    return Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, false);
}

From source file:Main.java

public static Bitmap effectChangeContrast(Bitmap bitmap, double effectLevel) {
    if (bitmap == null) {
        return bitmap;
    }//from   w w  w . j a v a  2s  .c o m

    Bitmap dst = bitmap.copy(Bitmap.Config.ARGB_8888, true);

    int height = dst.getHeight();
    int width = dst.getWidth();
    int[] pixels = new int[(width * height)];
    dst.getPixels(pixels, 0, width, 0, 0, width, height);

    for (int YY = 0; YY < width; ++YY) {
        for (int XX = 0; XX < height; ++XX) {
            int bitmapColor = pixels[(YY + XX * width)];
            int[] color = { Color.red(bitmapColor), Color.green(bitmapColor), Color.blue(bitmapColor) };

            if (color[0] > 200 && color[1] > 200 && color[3] > 200) {
                color[0] = 255;
                color[1] = 255;
                color[2] = 255;
            }

            for (int i = 0; i < color.length; i++) {
                int tmpColor = color[i];
                tmpColor = (int) ((tmpColor - 128) * effectLevel + 128);
                if (tmpColor < 0) {
                    tmpColor = 0;
                } else if (tmpColor > 255) {
                    tmpColor = 255;
                }
                color[i] = tmpColor;
            }

            pixels[(YY + XX * width)] = Color.rgb(color[0], color[1], color[2]);
        }
    }

    dst.setPixels(pixels, 0, width, 0, 0, width, height);
    return dst;
}

From source file:Main.java

private static Bitmap scaleBitmap(Bitmap bitmap, float ratio) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    Matrix matrix = new Matrix();
    matrix.postScale(1f / ratio, 1f / ratio);

    Bitmap result = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    return result;
}

From source file:Main.java

public static Bitmap resizeDownAndCropCenter(Bitmap bitmap, int size, boolean recycle) {
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    int minSide = Math.min(w, h);
    if (w == h && minSide <= size)
        return bitmap;
    size = Math.min(size, minSide);

    float scale = Math.max((float) size / bitmap.getWidth(), (float) size / bitmap.getHeight());
    Bitmap target = Bitmap.createBitmap(size, size, getConfig(bitmap));
    int width = Math.round(scale * bitmap.getWidth());
    int height = Math.round(scale * bitmap.getHeight());
    Canvas canvas = new Canvas(target);
    canvas.translate((size - width) / 2f, (size - height) / 2f);
    canvas.scale(scale, scale);/*from w  ww  . ja  va2 s .co  m*/
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG);
    canvas.drawBitmap(bitmap, 0, 0, paint);
    if (recycle)
        bitmap.recycle();
    return target;
}

From source file:Main.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) {

    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap

            .getHeight(), Config.ARGB_8888);

    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;

    final Paint paint = new Paint();

    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    final RectF rectF = new RectF(rect);

    paint.setAntiAlias(true);/*from  w  w w .  ja  va  2  s .c  om*/

    canvas.drawARGB(0, 0, 0, 0);

    paint.setColor(color);

    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;

}