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 rotaingBitmap(float degree, Bitmap bitmap) {
    Matrix matrix = new Matrix();
    matrix.postRotate(degree);// w w w  .ja  va  2  s  .c o m
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}

From source file:Main.java

public static Bitmap rotateBitmap(Bitmap bitmap) {

    Matrix matrix = new Matrix();
    matrix.postRotate(90f);/*ww  w. j  ava  2  s. c  o m*/

    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}

From source file:Main.java

public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h) {
    Bitmap newbmp = null;//from w w w. j  av a 2  s.c o  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);
        try {
            newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
        } catch (Exception e) {
            newbmp = bitmap;
        }
    }
    return newbmp;
}

From source file:Main.java

public static Rect[] layoutImagesInGrid(Bitmap destination, int cols, int rows) {
    int numItems = cols * rows;
    int itemWidth = destination.getWidth() / cols, itemHeight = destination.getHeight() / rows;

    Rect[] result = new Rect[numItems];

    for (int i = 0; i < numItems; i++) {
        int x = (i % cols) * itemWidth, y = (i / (rows + 1)) * itemHeight;
        Log.d(LOG_TAG, x + "x" + y);
        result[i] = new Rect(x, y, x + itemWidth, y + itemHeight);
    }//from  ww  w . j a va2  s  . c o  m

    return result;
}

From source file:Main.java

public static Bitmap toSepia(Bitmap bmpOriginal) {
    int width, height;
    height = bmpOriginal.getHeight();//from www. j  ava 2 s  .c  o m
    width = bmpOriginal.getWidth();

    Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
    Canvas c = new Canvas(bmpGrayscale);
    Paint paint = new Paint();

    ColorMatrix grMatrix = new ColorMatrix();
    grMatrix.setSaturation(0);

    ColorMatrix scMatrix = new ColorMatrix();
    scMatrix.setScale(1f, .85f, .72f, 1.0f);
    grMatrix.setConcat(scMatrix, grMatrix);

    ColorMatrixColorFilter f = new ColorMatrixColorFilter(grMatrix);
    paint.setColorFilter(f);
    c.drawBitmap(bmpOriginal, 0, 0, paint);
    return bmpGrayscale;
}

From source file:Main.java

private static Bitmap processBitmap(Bitmap bm) {

    float width = bm.getWidth();
    float height = bm.getHeight();
    int maxWidth = 150;
    int maxHeight = 150;
    float oldHeight;
    int oldWidth;
    float newWidth;
    float newHeight;
    float schnitt;

    Log.i("==============>", "width: " + width);
    Log.i("==============>", "height: " + height);

    newWidth = maxWidth;/*w w w. ja v a 2  s .com*/
    schnitt = newWidth / width;
    newHeight = (int) (schnitt * height);

    if (newHeight > maxHeight) {
        oldHeight = newHeight;
        oldWidth = (int) newWidth;
        newHeight = maxHeight;
        schnitt = newHeight / oldHeight;
        newWidth = schnitt * oldWidth;
    }

    Log.i("==============>", "New Width: " + newWidth);
    Log.i("==============>", "New Height: " + newHeight);

    bm = Bitmap.createScaledBitmap(bm, (int) newWidth, (int) newHeight, true);
    Log.i(I, "create scaled Bitmap successful");

    return bm;
}

From source file:Main.java

public static Bitmap resizeDownIfTooBig(final Bitmap bitmap, final int targetSize, final boolean recycle) {
    final int srcWidth = bitmap.getWidth();
    final int srcHeight = bitmap.getHeight();
    final float scale = Math.max((float) targetSize / srcWidth, (float) targetSize / srcHeight);
    if (scale > 0.5f)
        return bitmap;
    return resizeBitmapByScale(bitmap, scale, recycle);
}

From source file:Main.java

public static Drawable rotateBitmap(Bitmap inputBitmap) {
    Matrix matrix = new Matrix();
    matrix.setRotate(90, (float) inputBitmap.getWidth() / 2, (float) inputBitmap.getHeight() / 2);

    float outputX = inputBitmap.getHeight();
    float outputY = 0;

    final float[] values = new float[9];
    matrix.getValues(values);//from w  w  w  .j a  va  2s.  c o  m
    float x1 = values[Matrix.MTRANS_X];
    float y1 = values[Matrix.MTRANS_Y];
    matrix.postTranslate(outputX - x1, outputY - y1);
    Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap.getHeight(), inputBitmap.getWidth(),
            Bitmap.Config.ARGB_8888);
    Paint paint = new Paint();
    Canvas canvas = new Canvas(outputBitmap);
    canvas.drawBitmap(inputBitmap, matrix, paint);
    return new BitmapDrawable(null, outputBitmap);
}

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();
    point.y = bm.getHeight();/* ww  w. j av a 2 s  . co m*/
    bm.recycle();
    bm = null;

    return point;
}

From source file:Main.java

public static Bitmap divide(Bitmap bitmap1, Bitmap bitmap2) {
    double alpha = Double.MIN_VALUE;
    int width = bitmap1.getWidth();
    int height = bitmap1.getHeight();
    Bitmap grayBitmap1 = toGrayScale(bitmap1);
    Bitmap grayBitmap2 = toGrayScale(bitmap2);
    Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    for (int x = 0; x < width; x++)
        for (int y = 0; y < height; y++) {
            int value1 = Color.blue(grayBitmap1.getPixel(x, y));
            int value2 = Color.blue(grayBitmap2.getPixel(x, y));
            //                int resultValue = (int) (Math.abs((Math.log((value1 + alpha)/(value2 + alpha))) * 1000));
            int resultValue = (int) ((Math.abs(Math.log((value1 + alpha) / (value2 + alpha)))) * 255);
            result.setPixel(x, y, Color.rgb(resultValue, resultValue, resultValue));
        }/*ww  w. jav a2 s  .  c o  m*/
    //        grayBitmap1.recycle();
    //        grayBitmap2.recycle();
    return result;
}