Here you can find the source of roundByte(final double value)
public static int roundByte(final double value)
//package com.java2s; /*// w ww.j a v a2 s . c om * GeoTools - The Open Source Java GIS Toolkit * http://geotools.org * * (C) 2001-2008, Open Source Geospatial Foundation (OSGeo) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ public class Main { /** * Rounds a float value and clamp the result between 0 and 255 inclusive. */ public static int roundByte(final double value) { return (int) Math.min(Math.max(Math.round(value), 0), 255); } }