List of usage examples for java.lang Math round
public static long round(double a)
From source file:Main.java
private static String convertBase62ToDecimal(String ident62) { Long decimal = 0L;//from w ww . ja v a2 s. c om int base = 62; Long keisu = 0L; int cnt = 0; byte ident[] = ident62.getBytes(); for (int i = ident.length - 1; i >= 0; i--) { int num = 0; if (ident[i] > 48 && ident[i] <= 57) { num = ident[i] - 48; } else if (ident[i] >= 65 && ident[i] <= 90) { num = ident[i] - 65 + 10; } else if (ident[i] >= 97 && ident[i] <= 122) { num = ident[i] - 97 + 10 + 26; } keisu = Math.round(java.lang.Math.pow((double) base, (double) cnt)); decimal += num * keisu; cnt++; } return String.format("%08d", decimal); }
From source file:Main.java
public static int getZoomLevelAsInt(double zoomLevel) { return (int) Math.round(zoomLevel); }
From source file:Main.java
public static int calculateInSampleSize(int width, int height, int reqWidth, int reqHeight) { int inSampleSize = 1; if (height > reqHeight || width > reqWidth) { if (width > height) { inSampleSize = Math.round((float) height / (float) reqHeight); } else {//from www. j av a 2 s .co m inSampleSize = Math.round((float) width / (float) reqWidth); } } return inSampleSize; }
From source file:Main.java
/** * Convert RGB Color to a HSL values.//ww w .ja va 2 s.c om * * <li>H (Hue) is specified as degrees in the range 0 - 360.</li> * <li>S (Saturation) is specified as a percentage in the range 1 - 100.</li> * <li>L (Lumanance) is specified as a percentage in the range 1 - 100.</li> * * @param color the RGB color * @return the HSL values */ public static int[] colorToHSL(int color) { int[] hsl = new int[3]; float[] hsl_float = hslFromRGB(color); hsl[0] = (int) Math.round(hsl_float[0]); hsl[1] = (int) Math.round(hsl_float[1]); hsl[2] = (int) Math.round(hsl_float[2]); return hsl; }
From source file:Main.java
private static void rgb2cmyk(int R, int G, int B, int[] cmyk) { float C = 1 - (float) R / 255; float M = 1 - (float) G / 255; float Y = 1 - (float) B / 255; float K = 1;//w w w . ja v a2 s .com if (C < K) K = C; if (M < K) K = M; if (Y < K) K = Y; if (K == 1) { //pure black C = 0; M = 0; Y = 0; } else { C = (C - K) / (1 - K); M = (M - K) / (1 - K); Y = (Y - K) / (1 - K); } cmyk[0] = (int) Math.round(C * 100); cmyk[1] = (int) Math.round(M * 100); cmyk[2] = (int) Math.round(Y * 100); cmyk[3] = (int) Math.round(K * 100); }
From source file:Main.java
/** * Convert RGB Color to a HSV values. // w w w . ja v a 2s . c om * * <li>H (Hue) is specified as degrees in the range 0 - 360.</li> * <li>S (Saturation) is specified as a percentage in the range 1 - 100.</li> * <li>V (Value) is specified as a percentage in the range 1 - 100.</li> * * @param color the RGB color * @return the HSV values */ public static int[] colorToHSV(int color) { int[] hsv = new int[3]; float[] hsv_float = new float[3]; Color.colorToHSV(color, hsv_float); hsv[0] = (int) Math.round(hsv_float[0]); hsv[1] = (int) Math.round(hsv_float[1] * 100); hsv[2] = (int) Math.round(hsv_float[2] * 100); hsv[0] = (int) (hsv_float[0]); hsv[1] = (int) (hsv_float[1] * 100); hsv[2] = (int) (hsv_float[2] * 100); return hsv; }
From source file:Main.java
public static Bitmap Bytes2Bimap(byte[] bytes, int maxSize) { try {//w ww . j av a 2 s . com if (bytes == null) { return null; } if (bytes.length != 0) { BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inJustDecodeBounds = true; BitmapFactory.decodeByteArray(bytes, 0, bytes.length, opt); int scale = 1; if ((opt.outHeight > maxSize) || (opt.outWidth > maxSize)) { scale = (int) Math.pow(2, (int) Math.round( Math.log(maxSize / (double) Math.max(opt.outHeight, opt.outWidth)) / Math.log(0.5))); } BitmapFactory.Options newOpt = new BitmapFactory.Options(); newOpt.inSampleSize = scale; return BitmapFactory.decodeByteArray(bytes, 0, bytes.length, newOpt); } else { return null; } } catch (Exception ex) { return null; } }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static Bitmap blur(Context context, Bitmap image) { int width = Math.round(image.getWidth() * BITMAP_SCALE); int height = Math.round(image.getHeight() * BITMAP_SCALE); Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false); Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap); RenderScript rs = RenderScript.create(context); ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap); Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap); theIntrinsic.setRadius(BLUR_RADIUS); theIntrinsic.setInput(tmpIn);//from ww w . j ava 2s . c o m theIntrinsic.forEach(tmpOut); tmpOut.copyTo(outputBitmap); return outputBitmap; }
From source file:Main.java
public static int calculateInSampleSize(BitmapFactory.Options options, Context context) { int reqWidth = context.getResources().getDisplayMetrics().widthPixels; int reqHeight = context.getResources().getDisplayMetrics().heightPixels; // Raw height and width of image final int imgheight = options.outHeight; final int imgwidth = options.outWidth; int inSampleSize = 1; if (imgheight > reqHeight || imgwidth > reqWidth) { if (imgwidth > imgheight) { inSampleSize = Math.round((float) imgheight / (float) reqHeight); } else {/*from w w w . ja v a 2 s. com*/ inSampleSize = Math.round((float) imgwidth / (float) reqWidth); } } return inSampleSize; }
From source file:Main.java
static BufferedImage average(BufferedImage[] images) { BufferedImage average = new BufferedImage(images[0].getWidth(), images[0].getHeight(), BufferedImage.TYPE_BYTE_GRAY); WritableRaster raster = average.getRaster().createCompatibleWritableRaster(); for (int k = 0; k < images[0].getHeight(); ++k) { for (int j = 0; j < images[0].getWidth(); ++j) { float sum = 0.0f; for (int i = 0; i < images.length; ++i) { sum = sum + images[i].getRaster().getSample(j, k, 0); }//from ww w .jav a2s . c o m raster.setSample(j, k, 0, Math.round(sum / images.length)); } } average.setData(raster); return average; }