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

/**
 * TODO doc/*from w ww  .  java  2  s.  c om*/
 *
 * @param source
 * @return
 */
public static Bitmap flipHorizonallyBitmap(Bitmap source) {
    Matrix m = new Matrix();
    m.setScale(-1, 1);
    return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), m, false);
}

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  ww w.  j  a  v a2s .c  o m

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

    Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Bitmap.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, Shader.TileMode.CLAMP);
    paint.setShader(shader);
    // Set the Transfer mode to be porter duff and destination in
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.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

private static Bitmap drawToBitmap(Resources resources, int drawableResourceID, Bitmap bitmap) {
    Drawable drawable = resources.getDrawable(drawableResourceID);
    drawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
    drawable.draw(new Canvas(bitmap));
    return bitmap;
}

From source file:Main.java

public static double getAspectRatio(Bitmap bitmap) {
    if (bitmap == null)
        throw new IllegalArgumentException("bitmap is null");

    return (double) bitmap.getWidth() / (double) bitmap.getHeight();
}

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);/*from   w w w  .  ja v a2s. com*/

    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 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  ava2s. 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 Bitmap showPicture(Bitmap myBitmap, int rot) {
    Matrix matrix = new Matrix();
    matrix.postRotate(rot);//w w  w .j  a v  a 2 s.  c o m

    Bitmap scaledBitmap = Bitmap.createScaledBitmap(myBitmap, 320, 320, true);
    return Bitmap.createBitmap(scaledBitmap, 0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight(), matrix,
            true);
}

From source file:Main.java

public static Bitmap combineImagesToSameSize(Bitmap bgd, Bitmap fg) {
    Bitmap bmp;/*from w  ww  .  j a  v  a  2 s . com*/

    int width = bgd.getWidth() < fg.getWidth() ? bgd.getWidth() : fg.getWidth();
    int height = bgd.getHeight() < fg.getHeight() ? bgd.getHeight() : fg.getHeight();

    if (fg.getWidth() != width && fg.getHeight() != height) {
        fg = zoom(fg, width, height);
    }
    if (bgd.getWidth() != width && bgd.getHeight() != height) {
        bgd = zoom(bgd, width, height);
    }

    bmp = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Paint paint = new Paint();
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_ATOP));

    Canvas canvas = new Canvas(bmp);
    canvas.drawBitmap(bgd, 0, 0, null);
    canvas.drawBitmap(fg, 0, 0, paint);

    return bmp;
}

From source file:Main.java

@SuppressWarnings("unused")
private static Bitmap getBitmap(InputStream fs) {
    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inSampleSize = 1;//from   w w  w  .  j a v  a  2s. c om
    Bitmap imgBitmap = BitmapFactory.decodeStream(fs, null, opts);
    if (imgBitmap != null) {
        int width = imgBitmap.getWidth();
        int height = imgBitmap.getHeight();
        imgBitmap = Bitmap.createScaledBitmap(imgBitmap, width, height, true);
    }
    return imgBitmap;
}

From source file:Main.java

/**
 * calculate hashcode for a bitmap./*from   w w  w .  jav  a2s  . c  om*/
 * all pixels in the bitmap is considered for the hashcode, and if you want
 * a better performance for the calculation, use {@link #bitmap2hash(Bitmap)}.
 * @return hash code
 */
public static long bitmap2hashFull(Bitmap bitmap) {
    if (bitmap == null)
        return 0;
    long hash = 31;
    for (int x = 0; x < bitmap.getWidth(); x++) {
        for (int y = 0; y < bitmap.getHeight(); y++) {
            hash *= (bitmap.getPixel(x, y) + 31);
        }
    }
    return hash;
}