List of usage examples for java.lang Math ceil
public static double ceil(double a)
From source file:Main.java
private static int computeInitialSampleSize(BitmapFactory.Options options, int minSideLength, int maxNumOfPixels) { double w = options.outWidth; double h = options.outHeight; int lowerBound = (maxNumOfPixels == -1) ? 1 : (int) Math.ceil(Math.sqrt(w * h / maxNumOfPixels)); int upperBound = (minSideLength == -1) ? 128 : (int) Math.min(Math.floor(w / minSideLength), Math.floor(h / minSideLength)); if (upperBound < lowerBound) { // return the larger one when there is no overlapping zone. return lowerBound; }/*from w w w .jav a2s . com*/ if ((maxNumOfPixels == -1) && (minSideLength == -1)) { return 1; } else if (minSideLength == -1) { return lowerBound; } else { return upperBound; } }
From source file:Main.java
public static final Bitmap getBitmap(String fileName) { Bitmap bitmap = null;/*ww w. ja va 2s. com*/ try { Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(fileName, options); options.inSampleSize = Math.max(1, (int) Math .ceil(Math.max((double) options.outWidth / 1024f, (double) options.outHeight / 1024f))); options.inJustDecodeBounds = false; bitmap = BitmapFactory.decodeFile(fileName, options); } catch (OutOfMemoryError error) { error.printStackTrace(); } return bitmap; }
From source file:Main.java
public static int dp(float value, Context c) { density = c.getResources().getDisplayMetrics().density; return (int) Math.ceil(density * value); }
From source file:Main.java
public static Bitmap getMosaic(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); int radius = 10; Bitmap mosaicBitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(mosaicBitmap); int horCount = (int) Math.ceil(width / (float) radius); int verCount = (int) Math.ceil(height / (float) radius); Paint paint = new Paint(); paint.setAntiAlias(true);/*from ww w. j a v a 2s .co m*/ for (int horIndex = 0; horIndex < horCount; ++horIndex) { for (int verIndex = 0; verIndex < verCount; ++verIndex) { int l = radius * horIndex; int t = radius * verIndex; int r = l + radius; if (r > width) { r = width; } int b = t + radius; if (b > height) { b = height; } int color = bitmap.getPixel(l, t); Rect rect = new Rect(l, t, r, b); paint.setColor(color); canvas.drawRect(rect, paint); } } canvas.save(); return mosaicBitmap; }
From source file:Main.java
/** * Calculates how many hours are in given period. If one of the dates only partially covers the hour, it still counts as full hour. * * @param start Start of the period./*from ww w. j a va 2 s.c o m*/ * @param end End of the period. * @return Number of days in given period. If {@code end < start}, returns -1. */ public static int getHourCountInPeriod(long start, long end) { if (end < start) return -1; return (int) Math.ceil((double) (end - start) / DateUtils.HOUR_IN_MILLIS); }
From source file:Main.java
/** * Rounds a number to a given number of significant decimal digits. * Note that the number will be left with *only* this number of * significant digits regardless of magnitude, e.g. 12345 to 3 digits * will be 12300, whereas 0.12345 will be 0.123. * * @param value the value to round off.// w ww . j av a 2 s. c o m * @param n the number of significant decimal digits desired. * @return a rounded off number. */ public static double roundToSignificantDigits(double value, int n) { if (value == 0.0) { return 0.0; } final double d = Math.ceil(Math.log10(value < 0.0 ? -value : value)); final int power = n - (int) d; final double magnitude = Math.pow(10.0, power); final long shifted = Math.round(value * magnitude); return shifted / magnitude; }
From source file:Main.java
public static int calculateInSampleSizeMin(BitmapFactory.Options options, int reqWidth, int reqHeight) { // Raw height and width of image final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if (reqWidth == 0 || reqHeight == 0) return 1; if (height > reqHeight || width > reqWidth) { // Calculate ratios of height and width to requested height and width final int heightRatio = (int) Math.ceil((float) height / (float) reqHeight); final int widthRatio = (int) Math.ceil((float) width / (float) reqWidth); // Choose the smallest ratio as inSampleSize value, this will guarantee // a final image with both dimensions larger than or equal to the // requested height and width. inSampleSize = heightRatio > widthRatio ? heightRatio : widthRatio; }/* w w w . ja v a2s .co m*/ return inSampleSize; }
From source file:Main.java
public static Bitmap scaleToFillBitmap(Bitmap dst, InputStream is) { Bitmap src = BitmapFactory.decodeStream(is); float scaled = 1.0f; if ((float) dst.getWidth() / (float) src.getWidth() < (float) dst.getHeight() / (float) src.getHeight()) { scaled = (float) dst.getHeight() / (float) src.getHeight(); } else {// w w w.j a v a 2 s . co m scaled = (float) dst.getWidth() / (float) src.getWidth(); } Bitmap bmpScaled = Bitmap.createScaledBitmap(src, (int) Math.ceil(src.getWidth() * scaled), (int) Math.ceil(src.getHeight() * scaled), true); int offsetX = 0; int offsetY = 0; offsetX = bmpScaled.getWidth() - dst.getWidth() != 0 ? (bmpScaled.getWidth() - dst.getWidth()) / 2 : 0; offsetY = bmpScaled.getHeight() - dst.getHeight() != 0 ? (bmpScaled.getHeight() - dst.getHeight()) / 2 : 0; return Bitmap.createBitmap(bmpScaled, offsetX, offsetY, dst.getWidth(), dst.getHeight()); }
From source file:Main.java
public static int ceil(int value1, float value2) { return (int) Math.ceil(value1 / value2); }
From source file:Main.java
public static int getSampleSize(double width, double screenWidth) { return (int) Math.ceil(width / screenWidth); }