Example usage for android.graphics Bitmap equals

List of usage examples for android.graphics Bitmap equals

Introduction

In this page you can find the example usage for android.graphics Bitmap equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:Main.java

public static Bitmap decodeBitmap(File file, int dstWidth, int dstHeight) {
    // First decode with inJustDecodeBounds=true to check dimensions
    final Options options = new Options();
    options.inScaled = false;/*ww  w  . ja  v  a2 s  .  c  o  m*/
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(file.getAbsolutePath(), options);

    // Decode the bitmap with inSampleSize set
    options.inSampleSize = calculateBitmapRatio(options, dstWidth, dstHeight);
    options.inJustDecodeBounds = false;
    Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
    if (bitmap == null) {
        return null;
    }

    // Test if the bitmap has exif format, and decode properly
    Bitmap out = decodeExifBitmap(file, bitmap);
    if (!out.equals(bitmap)) {
        bitmap.recycle();
    }
    return out;
}

From source file:Main.java

public static Bitmap getRotatedBitmap(Bitmap bitmap, int degrees) {
    if (degrees != 0 && bitmap != null) {
        Matrix m = new Matrix();
        m.setRotate(degrees, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2);
        try {//from w  ww .j  ava2s . com
            Bitmap b2 = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true);
            if (bitmap.equals(b2)) {
                bitmap.recycle();
                bitmap = b2;
            }
        } catch (OutOfMemoryError ex) {
            // TODO Auto-generated catch block
            ex.printStackTrace();
        }
    }
    return bitmap;
}

From source file:com.snipme.download.ImageDownloader.java

public static boolean checkifImageExists(String imagename) {
    Bitmap b = null;
    File file = ImageStorage.getImage("/" + imagename + ".jpg");
    String path = file.getAbsolutePath();

    if (path != null)
        b = BitmapFactory.decodeFile(path);

    if (b == null || b.equals("")) {
        return false;
    }/*from  ww w  .  ja  v  a 2  s . c  om*/
    return true;
}

From source file:com.ruesga.rview.misc.BitmapUtils.java

@SuppressWarnings("deprecation")
public static Bitmap decodeBitmap(File file, int dstWidth, int dstHeight) {
    // First decode with inJustDecodeBounds=true to check dimensions
    final Options options = new Options();
    options.inScaled = false;/*from   w  ww  .  j  a v a  2  s .  co m*/
    options.inDither = true;
    options.inPreferQualityOverSpeed = false;
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    // Deprecated, but still valid for KitKat and lower apis
    options.inPurgeable = true;
    options.inInputShareable = true;
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(file.getAbsolutePath(), options);

    // Decode the bitmap with inSampleSize set
    options.inSampleSize = calculateBitmapRatio(options, dstWidth, dstHeight);
    options.inJustDecodeBounds = false;
    Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
    if (bitmap == null) {
        return null;
    }

    // Test if the bitmap has exif format, and decode properly
    Bitmap out = decodeExifBitmap(file, bitmap);
    if (out != null && !out.equals(bitmap)) {
        bitmap.recycle();
    }
    return out;
}

From source file:org.mozilla.gecko.Tab.java

public void updateThumbnail(final Bitmap b) {
    final Tab tab = this;
    GeckoAppShell.getHandler().post(new Runnable() {
        public void run() {
            if (b != null) {
                try {
                    Bitmap cropped = null;
                    /* Crop to screen width if the bitmap is larger than the screen width or height. If smaller and the
                     * the aspect ratio is correct, just use the bitmap as is. Otherwise, fit the smaller
                     * smaller dimension, then crop the larger dimention.
                     *//*from  ww  w. ja va2 s  .c o  m*/
                    if (getMinScreenshotWidth() < b.getWidth() && getMinScreenshotHeight() < b.getHeight())
                        cropped = Bitmap.createBitmap(b, 0, 0, getMinScreenshotWidth(),
                                getMinScreenshotHeight());
                    else if (b.getWidth() * getMinScreenshotHeight() == b.getHeight() * getMinScreenshotWidth())
                        cropped = b;
                    else if (b.getWidth() * getMinScreenshotHeight() < b.getHeight() * getMinScreenshotWidth())
                        cropped = Bitmap.createBitmap(b, 0, 0, b.getWidth(),
                                b.getWidth() * getMinScreenshotHeight() / getMinScreenshotWidth());
                    else
                        cropped = Bitmap.createBitmap(b, 0, 0,
                                b.getHeight() * getMinScreenshotWidth() / getMinScreenshotHeight(),
                                b.getHeight());

                    Bitmap bitmap = Bitmap.createScaledBitmap(cropped, getThumbnailWidth(),
                            getThumbnailHeight(), false);
                    saveThumbnailToDB(new BitmapDrawable(bitmap));

                    if (!cropped.equals(b))
                        b.recycle();
                    mThumbnail = new BitmapDrawable(bitmap);
                    cropped.recycle();
                } catch (OutOfMemoryError oom) {
                    Log.e(LOGTAG, "Unable to create/scale bitmap", oom);
                    mThumbnail = null;
                }
            } else {
                mThumbnail = null;
            }
            GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
                public void run() {
                    GeckoApp.mAppContext.onTabsChanged(tab);
                }
            });
        }
    });
}