List of usage examples for java.lang Math min
@HotSpotIntrinsicCandidate public static double min(double a, double b)
From source file:Main.java
public static Bitmap cropCenter(Bitmap bitmap, boolean recycle) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); if (width == height) return bitmap; int size = Math.min(width, height); Bitmap target = Bitmap.createBitmap(size, size, getConfig(bitmap)); Canvas canvas = new Canvas(target); canvas.translate((size - width) / 2, (size - height) / 2); Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(bitmap, 0, 0, paint); if (recycle)// w ww.j ava2 s. c o m bitmap.recycle(); return target; }
From source file:Main.java
public static int[] getExtremeCoords(List<int[]> positions, boolean min) { if (positions.size() > 0) { int[] selectedPos = positions.get(0).clone(); for (int n = 1; n < positions.size(); n++) { int[] position = positions.get(n); for (int i = 0; i < selectedPos.length; i++) { selectedPos[i] = min ? Math.min(position[i], selectedPos[i]) : Math.max(position[i], selectedPos[i]); }/*from ww w. j a v a 2s . c o m*/ } return selectedPos; } return null; }
From source file:Main.java
private static int computeInitialSampleSize(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; }// www . j a v a 2s . c om if ((maxNumOfPixels == -1) && (minSideLength == -1)) { return 1; } else if (minSideLength == -1) { return lowerBound; } else { return upperBound; } }
From source file:Main.java
private static byte[] getBytesFromDriveVideoUri(Context context, Uri uri) { InputStream inputStream = null; try {/*w w w. j av a 2 s. c o m*/ inputStream = context.getContentResolver().openInputStream(uri); } catch (FileNotFoundException e) { e.printStackTrace(); } if (inputStream == null) { return null; } int maxBufferSize = 1024 * 1024; int available = 0; try { available = inputStream.available(); } catch (IOException e) { e.printStackTrace(); } if (available == 0) { available = maxBufferSize; } int bufferSize = Math.min(available, maxBufferSize); byte[] data = new byte[bufferSize]; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int nRead; try { while ((nRead = inputStream.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } } catch (IOException e) { e.printStackTrace(); } try { buffer.flush(); } catch (IOException e) { e.printStackTrace(); } return buffer.toByteArray(); }
From source file:Main.java
static public Object expandArray(Object[] list, int newSize) { Class type = list.getClass().getComponentType(); Object temp = Array.newInstance(type, newSize); System.arraycopy(list, 0, temp, 0, Math.min(Array.getLength(list), newSize)); return temp;/* www .j a v a2s . com*/ }
From source file:Main.java
public static Bitmap resizeDownBySideLength(Bitmap bitmap, int maxLength, boolean recycle) { int srcWidth = bitmap.getWidth(); int srcHeight = bitmap.getHeight(); float scale = Math.min((float) maxLength / srcWidth, (float) maxLength / srcHeight); if (scale >= 1.0f) return bitmap; return resizeBitmapByScale(bitmap, scale, recycle); }
From source file:Main.java
public static <T> List<List<T>> partition(List<T> list, int partitionSize) { List<List<T>> results = new LinkedList<>(); for (int index = 0; index < list.size(); index += partitionSize) { int subListSize = Math.min(partitionSize, list.size() - index); results.add(list.subList(index, index + subListSize)); }/*from w ww .j a va 2 s .c o m*/ return results; }
From source file:Main.java
/** * Gets the proper scale value that scales down the content and keeps its aspect ratio to * display inside the view.//w ww. java2s . c om */ public static float getDisplayScale(RectF contentBounds, View view) { if (contentBounds.isEmpty()) { return 1; } float scale = Math.min(view.getWidth() / contentBounds.width(), view.getHeight() / contentBounds.height()); // Avoid scaling up the content. return Math.min(scale, 1); }
From source file:Main.java
public static Bitmap scaleAndFrame(Bitmap bitmap, int width, int height) { final int bitmapWidth = bitmap.getWidth(); final int bitmapHeight = bitmap.getHeight(); final float scale = Math.min((float) width / (float) bitmapWidth, (float) height / (float) bitmapHeight); final int scaledWidth = (int) (bitmapWidth * scale); final int scaledHeight = (int) (bitmapHeight * scale); final Bitmap decored = Bitmap.createScaledBitmap(bitmap, scaledWidth, scaledHeight, true); final Canvas canvas = new Canvas(decored); final int offset = (int) (PHOTO_BORDER_WIDTH / 2); sStrokePaint.setAntiAlias(false);/*from w ww. j ava 2s . co m*/ canvas.drawRect(offset, offset, scaledWidth - offset - 1, scaledHeight - offset - 1, sStrokePaint); sStrokePaint.setAntiAlias(true); return decored; }
From source file:Main.java
public static String maskDebugInfo(Object info) { if (info == null) return null; String s = info.toString();//from w ww . j av a 2s . c om int length = Math.min(s.length(), MASK_STRING.length()); return IS_DEBUG_BUILD ? s : MASK_STRING.substring(0, length); }