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 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  w w .  j av  a 2s  .c om*/
    paint.setColorFilter(new ColorMatrixColorFilter(matrix));
    canvas.drawBitmap(source, 0, 0, paint);
    return output;
}

From source file:Main.java

public static float getValue(Bitmap bitmap, int x, int y) {
    if (x < 0 || y < 0 || x > (bitmap.getWidth() - 1) || y > (bitmap.getHeight() - 1))
        Log.d("GET PIXEL ERROR!!!!!!!!!!!!",
                "X,Y is " + x + "," + y + "\tmax X,Y is" + bitmap.getWidth() + "," + bitmap.getHeight());
    int color = bitmap.getPixel(x, y);
    int red = Color.red(color);
    int green = Color.green(color);
    int blue = Color.blue(color);
    float intensity = (float) (0.299 * red + 0.587 * green + 0.114 * blue);
    return intensity;
}

From source file:Main.java

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

From source file:Main.java

/**
 * center crop to target size.// w  w  w . j av a  2s. c o  m
 */
public static Bitmap centerCropBitmap(Bitmap srcBmp, int destSize) {
    int srcWidth = srcBmp.getWidth();
    int srcHeight = srcBmp.getHeight();
    if (srcWidth >= srcHeight) {
        destSize = destSize <= srcHeight ? destSize : srcHeight;
    } else {
        destSize = destSize <= srcWidth ? destSize : srcWidth;
    }
    return Bitmap.createBitmap(srcBmp, srcWidth / 2 - destSize / 2, srcHeight / 2 - destSize / 2, destSize,
            destSize);
}

From source file:Main.java

public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix matrix = new Matrix();
    float x = (float) w / width;
    float y = (float) h / height;
    matrix.postScale(x, y);//from   ww w.  j  av  a  2 s.  co  m
    Bitmap zoomBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    return zoomBitmap;
}

From source file:Main.java

public static Bitmap scaleBitmap(Bitmap source, int targetSize) {
    int sourceW = source.getWidth();
    int sourceH = source.getHeight();

    float scaleFactor = (float) Math.sqrt(source.getByteCount() / targetSize);

    int dstWidth = (int) (sourceW / scaleFactor);
    int dstHeight = (int) (sourceH / scaleFactor);

    Bitmap scaledBitmap = createScaledBitmap(source, dstWidth, dstHeight, true);
    return scaledBitmap;
}

From source file:Main.java

public static Bitmap blackAndWhited(Bitmap in) {
    int width = in.getWidth();
    int height = in.getHeight();

    int[] pixels = new int[width * height];
    in.getPixels(pixels, 0, width, 0, 0, width, height);
    int alpha = 0xFF << 24;
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            int grey = pixels[width * i + j];
            int red = ((grey & 0x00FF0000) >> 16);
            int green = ((grey & 0x0000FF00) >> 8);
            int blue = (grey & 0x000000FF);
            grey = (int) (red * 0.3 + green * 0.59 + blue * 0.11);
            grey = alpha | (grey << 16) | (grey << 8) | grey;
            pixels[width * i + j] = grey;
        }//w w  w .  j  a  v  a 2 s.com
    }
    Bitmap newBmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
    newBmp.setPixels(pixels, 0, width, 0, 0, width, height);
    return newBmp;
}

From source file:Main.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    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);
    final float roundPx = bitmap.getWidth() / 2;

    paint.setAntiAlias(true);/*w  w  w. j a  v  a 2s  .c o m*/
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}

From source file:Main.java

public static Bitmap scaleToFitHeight(Bitmap bitmap, int i) {
    return Bitmap.createScaledBitmap(bitmap,
            (int) (((float) i / (float) bitmap.getHeight()) * (float) bitmap.getWidth()), i, false);
}

From source file:Main.java

public static Bitmap cutBitmap(Bitmap bitmap, int nwidth, int nHeight) {
    if (null == bitmap || nwidth > bitmap.getWidth() || nHeight > bitmap.getHeight()) {
        return null;
    }//from w w w.j  a v a2 s. co m
    Bitmap result = Bitmap.createBitmap(bitmap, 0, 0, nwidth, nHeight);
    return result;
}