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

static public Bitmap scaleToFill(Bitmap b, int width, int height) {
    float factorH = height / (float) b.getWidth();
    float factorW = width / (float) b.getWidth();
    float factorToUse = (factorH > factorW) ? factorW : factorH;
    return Bitmap.createScaledBitmap(b, (int) (b.getWidth() * factorToUse), (int) (b.getHeight() * factorToUse),
            false);//from   w w  w .  j a v a2s. com
}

From source file:Main.java

public static Bitmap applySaturationFilter(Bitmap source, int level) {
    int width = source.getWidth();
    int height = source.getHeight();
    int[] pixels = new int[width * height];
    float[] HSV = new float[3];
    source.getPixels(pixels, 0, width, 0, 0, width, height);

    int index = 0;
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            index = y * width + x;//  w w w  .j  ava2 s. c  om
            Color.colorToHSV(pixels[index], HSV);
            HSV[1] *= level;
            HSV[1] = (float) Math.max(0.0, Math.min(HSV[1], 1.0));
            pixels[index] |= Color.HSVToColor(HSV);
        }
    }
    Bitmap bmOut = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bmOut.setPixels(pixels, 0, width, 0, 0, width, height);
    return bmOut;
}

From source file:Main.java

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

From source file:Main.java

public static Bitmap scale(Bitmap b, float scale) {
    Bitmap res = Bitmap.createBitmap((int) (b.getWidth() * scale + .5f), (int) (b.getHeight() * scale + .5f),
            b.getConfig());/*from  www. ja  v a 2  s  . c  o  m*/
    Canvas c = new Canvas(res);
    c.scale(scale, scale);
    c.drawBitmap(b, 0, 0, scalePaint);
    return res;
}

From source file:Main.java

public static Bitmap cropCenterInside(Bitmap src, Rect rect) {
    int width = Math.min(src.getWidth(), rect.width());
    int height = Math.min(src.getHeight(), rect.height());
    int[] rowData = new int[width];
    int stride = src.getWidth();
    int x = (src.getWidth() - width) / 2;
    int y = (src.getHeight() - height) / 2;

    Bitmap dest = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);

    int delta = 0;
    while (delta < height) {
        src.getPixels(rowData, 0, stride, x, y + delta, width, 1);
        dest.setPixels(rowData, 0, stride, 0, delta, width, 1);
        delta++;/*  w ww .  jav  a2 s  .c  o m*/
    }
    return dest;
}

From source file:Main.java

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

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

    Canvas canvas = new Canvas(output);
    Paint paint = new Paint();
    Rect rect = new Rect(0, 0, width, height);

    paint.setAntiAlias(true);//www . j ava 2 s  . c o m
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawCircle(width / 2, height / 2, width / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, null, rect, paint);
    return output;
}

From source file:Main.java

/**
 * draw the image to viewBitmap in fill mode.
 * @param viewBitmap Bitmap to be displayed on the device.
 * @param bitmap Bitmap image./*from w ww  . j a  v a 2  s  .  co  m*/
 */
public static void drawImageForFillsMode(final Bitmap viewBitmap, final Bitmap bitmap) {

    float getSizeW = bitmap.getWidth();
    float getSizeH = bitmap.getHeight();

    Canvas canvas = new Canvas(viewBitmap);

    final int width = viewBitmap.getWidth();
    final int height = viewBitmap.getHeight();
    for (int drawY = 0; drawY <= height; drawY += getSizeH) {
        for (int drawX = 0; drawX <= width; drawX += getSizeW) {
            canvas.drawBitmap(bitmap, drawX, drawY, null);
        }
    }
}

From source file:Main.java

public static Bitmap scaleToFill(Bitmap bitmap, int i, int j) {
    float f = (float) j / (float) bitmap.getWidth();
    float f1 = (float) i / (float) bitmap.getWidth();
    float f2;/*  w  w  w  . j  a v a  2s .co m*/
    if (f > f1) {
        f2 = f1;
    } else {
        f2 = f;
    }
    return Bitmap.createScaledBitmap(bitmap, (int) (f2 * (float) bitmap.getWidth()),
            (int) (f2 * (float) bitmap.getHeight()), false);
}

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 Bitmap resizeImage(Bitmap bitmap, int newWidth, int newHeight) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;

    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);

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