Package pi.resources
Class Codec
java.lang.Object
pi.resources.Codec
- Author:
- Steffen Wilke, Matthias Wilke
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]Decodes the specifiedBase64string to a byte array.static floatdecodeAngle(byte encodedAngle) Decodes a previously encoded angle.static floatdecodeAngle(short encodedAngle) static BufferedImagedecodeImage(String imageString) Dekodiert einen als String codierten Bildinhalt in einBufferedImageund konvertiert das Ergebnis in ein plattformkompatibles Bildformat.static floatdecodeSmallFloatingPointNumber(short encodedNumber, int precision) Decodes a small floating point number, previously encoded withencodeSmallFloatingPointNumber.static Stringencode(byte[] data) static Stringencode(BufferedImage image) static Stringencode(BufferedImage image, ImageFormat imageFormat) Kodiert einBufferedImagein eine Base64-String-Repräsentation anhand des angegebenen Bildformats.static byteencodeAngle(float angle) Encodes an angle, loosing some precision.static shortencodeAnglePrecise(float angle) static shortencodeSmallFloatingPointNumber(float smallNumber, int precision) Encodes positive numbers less than Short.MAX_VALUE * 2 / precision (6553.4 for precision = 1).
-
Method Details
-
decodeAngle
public static float decodeAngle(byte encodedAngle) Decodes a previously encoded angle.- Parameters:
encodedAngle- The encoded angle.- Returns:
- The decoded angle.
-
decodeAngle
public static float decodeAngle(short encodedAngle) -
decodeSmallFloatingPointNumber
public static float decodeSmallFloatingPointNumber(short encodedNumber, int precision) Decodes a small floating point number, previously encoded withencodeSmallFloatingPointNumber.- Parameters:
encodedNumber- The encoded numberprecision- The precision of the encoded number. The same precision, used for encoding.- Returns:
- The decoded small floating point number.
-
encodeAngle
public static byte encodeAngle(float angle) Encodes an angle, loosing some precision. The encoded / decoded values can differ at max. around 1.43 degrees from the original one.- Parameters:
angle- The angle- Returns:
- The encoded angle.
-
encodeAnglePrecise
public static short encodeAnglePrecise(float angle) -
encodeSmallFloatingPointNumber
public static short encodeSmallFloatingPointNumber(float smallNumber, int precision) Encodes positive numbers less than Short.MAX_VALUE * 2 / precision (6553.4 for precision = 1).- Parameters:
smallNumber- The small number to encodeprecision- The comma precision for the encoding process.- Returns:
- The encoded number.
-
decodeImage
Dekodiert einen als String codierten Bildinhalt in einBufferedImageund konvertiert das Ergebnis in ein plattformkompatibles Bildformat.Der Eingabestring wird zunächst in ein Byte-Array dekodiert und anschließend über
ImageIOeingelesen. Tritt während der Verarbeitung ein Fehler auf, wird dieser protokolliert.- Parameters:
imageString- der codierte Bildinhalt (z. B. Base64); darf nichtnullsein- Returns:
- das dekodierte, kompatible Bild; kann je nach Fehlerfall
nullsein - Throws:
IllegalArgumentException- wennimageString == nullRuntimeException- wenn
-
encode
-
encode
Kodiert einBufferedImagein eine Base64-String-Repräsentation anhand des angegebenen Bildformats.Ist das übergebene
imageFormatImageFormat.UNSUPPORTED, wird stattdessenImageFormat.PNGals Standardformat verwendet. Tritt während der Bildverarbeitung einIOExceptionauf, wird der Fehler protokolliert und es kannnullzurückgegeben werden.- Parameters:
image- das zu kodierende Bild; darf nichtnullseinimageFormat- das gewünschte Bildformat für die Kodierung- Returns:
- die kodierte Base64-Repräsentation des Bildes oder
null, falls die Kodierung aufgrund eines Fehlers nicht erfolgreich war - Throws:
IllegalArgumentException- wennimagenullist
-
encode
-
decode
Decodes the specifiedBase64string to a byte array.- Parameters:
base64- The Base64 string containing the encoded binary data.- Returns:
- The decoded byte array.
- See Also:
-