Example usage for android.graphics Canvas getMaximumBitmapHeight

List of usage examples for android.graphics Canvas getMaximumBitmapHeight

Introduction

In this page you can find the example usage for android.graphics Canvas getMaximumBitmapHeight.

Prototype

public int getMaximumBitmapHeight() 

Source Link

Document

Returns the maximum allowed height for bitmaps drawn with this canvas.

Usage

From source file:Main.java

/**
 * This method calculates maximum size of both width and height of bitmap.
 * It is twice the device screen diagonal for default implementation (extra quality to zoom image).
 * Size cannot exceed max texture size./*from ww  w . j  a va2  s  . c o m*/
 *
 * @return - max bitmap size in pixels.
 */
@SuppressWarnings({ "SuspiciousNameCombination", "deprecation" })
public static int calculateMaxBitmapSize(@NonNull Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    Point size = new Point();
    int width, height;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(size);
        width = size.x;
        height = size.y;
    } else {
        width = display.getWidth();
        height = display.getHeight();
    }

    int screenDiagonal = (int) Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));

    Canvas canvas = new Canvas();
    return Math.min(screenDiagonal * 2,
            Math.min(canvas.getMaximumBitmapWidth(), canvas.getMaximumBitmapHeight()));
}

From source file:com.hippo.largeimageview.LargeImageView.java

private int getMaxBitmapSize(Canvas canvas) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        int maxSize = Math.min(canvas.getMaximumBitmapWidth(), canvas.getMaximumBitmapHeight());
        // If hardware acceleration is not enabled,
        // getMaximumBitmapWidth() and getMaximumBitmapHeight()
        // will return Integer.MAX_VALUE.
        // In that case, use 2048 as default.
        if (maxSize == Integer.MAX_VALUE) {
            maxSize = 2048;/*from w ww  .j av  a  2 s. c o  m*/
        }
        return maxSize;
    } else {
        // Before ICE_CREAM_SANDWICH, hardware acceleration is not supported,
        // bitmap max size is not limited.
        // Use 2048 as default.
        return 2048;
    }
}