Java Code Examples for android.graphics.Bitmap.sameAs()

The following are Jave code examples for showing how to use sameAs() of the android.graphics.Bitmap class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: asaf-project   File: DrawableMatcher.java   View Source Code Vote up 7 votes
@Override
protected boolean matchesSafely(View target) {
    if (!(target instanceof ImageView)) {
        return false;
    }
    ImageView imageView = (ImageView) target;
    if (expectedId == EMPTY) {
        return imageView.getDrawable() == null;
    }
    if (expectedId == ANY) {
        return imageView.getDrawable() != null;
    }
    Resources resources = target.getContext().getResources();
    Drawable expectedDrawable = resources.getDrawable(expectedId);
    resourceName = resources.getResourceEntryName(expectedId);

    if (expectedDrawable == null) {
        return false;
    }

    Bitmap bitmap = getBitmap(imageView.getDrawable());
    Bitmap otherBitmap = getBitmap(expectedDrawable);
    return bitmap.sameAs(otherBitmap);
}
 
Example 2
Project: MaterialOCR   File: BitmapLoadUtils.java   View Source Code Vote up 5 votes
public static Bitmap transformBitmap(@NonNull Bitmap bitmap, @NonNull Matrix transformMatrix) {
    try {
        Bitmap converted = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), transformMatrix, true);
        if (!bitmap.sameAs(converted)) {
            bitmap = converted;
        }
    } catch (OutOfMemoryError error) {
        Log.e(TAG, "transformBitmap: ", error);
    }
    return bitmap;
}
 
Example 3
Project: Tusky   File: DownsizeImageTask.java   View Source Code Vote up 4 votes
@Nullable
private static Bitmap reorientBitmap(Bitmap bitmap, int orientation) {
    Matrix matrix = new Matrix();
    switch (orientation) {
        default:
        case ExifInterface.ORIENTATION_NORMAL: {
            return bitmap;
        }
        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: {
            matrix.setScale(-1, 1);
            break;
        }
        case ExifInterface.ORIENTATION_ROTATE_180: {
            matrix.setRotate(180);
            break;
        }
        case ExifInterface.ORIENTATION_FLIP_VERTICAL: {
            matrix.setRotate(180);
            matrix.postScale(-1, 1);
            break;
        }
        case ExifInterface.ORIENTATION_TRANSPOSE: {
            matrix.setRotate(90);
            matrix.postScale(-1, 1);
            break;
        }
        case ExifInterface.ORIENTATION_ROTATE_90: {
            matrix.setRotate(90);
            break;
        }
        case ExifInterface.ORIENTATION_TRANSVERSE: {
            matrix.setRotate(-90);
            matrix.postScale(-1, 1);
            break;
        }
        case ExifInterface.ORIENTATION_ROTATE_270: {
            matrix.setRotate(-90);
            break;
        }
    }
    try {
        Bitmap result = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
                bitmap.getHeight(), matrix, true);
        if (!bitmap.sameAs(result)) {
            bitmap.recycle();
        }
        return result;
    } catch (OutOfMemoryError e) {
        return null;
    }
}