Fields Summary |
---|
public static final String | V22_JPG_FORMAT |
public static final String | V22_PNG_FORMAT |
public static final String | V22_GIF_FORMAT |
public static final String | V22_BMP_FORMAT |
public static final String | V22_TIF_FORMAT |
public static final String | V22_PDF_FORMAT |
public static final String | V22_PIC_FORMAT |
public static final String | MIME_TYPE_JPEG |
public static final String | MIME_TYPE_PNG |
public static final String | MIME_TYPE_GIF |
public static final String | MIME_TYPE_BMP |
public static final String | MIME_TYPE_TIFF |
public static final String | MIME_TYPE_PDF |
public static final String | MIME_TYPE_PICT |
public static final String | MIME_TYPE_JPGSometimes this is used for jpg instead :or have I made this up |
private static Map | imageFormatsToMimeType |
private static Map | imageMimeTypeToFormat |
Methods Summary |
---|
public static boolean | binaryDataIsBmpFormat(byte[] data)Is this binary data a bmp image
//Read signature
return (0x42 == (data[0] & 0xff)) && (0x4d == (data[1] & 0xff));
|
public static boolean | binaryDataIsGifFormat(byte[] data)Is this binary data a gif image
if(data.length<3)
{
return false;
}
//Read signature
return (0x47 == (data[0] & 0xff)) && (0x49 == (data[1] & 0xff)) && (0x46 == (data[2] & 0xff));
|
public static boolean | binaryDataIsJpgFormat(byte[] data)Is this binary data a jpg image
if(data.length<4)
{
return false;
}
//Read signature
//Can be FF D8 FF E0 or FF D8 FF E1
//FF D8 is SOI Marker, FFE0 or FFE1 is JFIF Marker
return (0xff == (data[0] & 0xff)) && (0xd8 == (data[1] & 0xff)) && (0xff == (data[2] & 0xff)) && (0xe0 <= (data[3] & 0xff));
|
public static boolean | binaryDataIsPdfFormat(byte[] data)Is this binary data a pdf image
Details at http://en.wikipedia.org/wiki/Magic_number_%28programming%29
//Read signature
return (0x25 == (data[0] & 0xff)) && (0x50 == (data[1] & 0xff)) && (0x44 == (data[2] & 0xff)) && (0x46 == (data[3] & 0xff));
|
public static boolean | binaryDataIsPngFormat(byte[] data)Is this binary data a png image
//Read signature
if(data.length<4)
{
return false;
}
return (0x89 == (data[0] & 0xff)) && (0x50 == (data[1] & 0xff)) && (0x4E == (data[2] & 0xff)) && (0x47 == (data[3] & 0xff));
|
public static boolean | binaryDataIsTiffFormat(byte[] data)is this binary data a tiff image
Details at http://en.wikipedia.org/wiki/Magic_number_%28programming%29
//Read signature Intel
return (
((0x49 == (data[0] & 0xff)) && (0x49 == (data[1] & 0xff)) && (0x2a == (data[2] & 0xff)) && (0x00 == (data[3] & 0xff)))
||
((0x4d == (data[0] & 0xff)) && (0x4d == (data[1] & 0xff)) && (0x00 == (data[2] & 0xff)) && (0x2a == (data[3] & 0xff)))
);
|
public static java.lang.String | getFormatForMimeType(java.lang.String mimeType)Get v2.2 format from v2.3 mimetype
return imageMimeTypeToFormat.get(mimeType);
|
public static java.lang.String | getMimeTypeForBinarySignature(byte[] data)
if(binaryDataIsPngFormat(data))
{
return MIME_TYPE_PNG;
}
else if(binaryDataIsJpgFormat(data))
{
return MIME_TYPE_JPEG;
}
else if(binaryDataIsGifFormat(data))
{
return MIME_TYPE_GIF;
}
else if(binaryDataIsBmpFormat(data))
{
return MIME_TYPE_BMP;
}
else if(binaryDataIsPdfFormat(data))
{
return MIME_TYPE_PDF;
}
else if(binaryDataIsTiffFormat(data))
{
return MIME_TYPE_TIFF;
}
else
{
return null;
}
|
public static java.lang.String | getMimeTypeForFormat(java.lang.String format)Get v2.3 mimetype from v2.2 format
imageFormatsToMimeType.put(V22_JPG_FORMAT, MIME_TYPE_JPEG);
imageFormatsToMimeType.put(V22_PNG_FORMAT, MIME_TYPE_PNG);
imageFormatsToMimeType.put(V22_GIF_FORMAT, MIME_TYPE_GIF);
imageFormatsToMimeType.put(V22_BMP_FORMAT, MIME_TYPE_BMP);
imageFormatsToMimeType.put(V22_TIF_FORMAT, MIME_TYPE_TIFF);
imageFormatsToMimeType.put(V22_PDF_FORMAT, MIME_TYPE_PDF);
imageFormatsToMimeType.put(V22_PIC_FORMAT, MIME_TYPE_PICT);
String value;
for (String key : imageFormatsToMimeType.keySet())
{
value = imageFormatsToMimeType.get(key);
imageMimeTypeToFormat.put(value, key);
}
//The mapping isn't one-one lets add other mimetypes
imageMimeTypeToFormat.put(MIME_TYPE_JPG, V22_JPG_FORMAT);
return imageFormatsToMimeType.get(format);
|
public static boolean | isPortableFormat(byte[] data)
return binaryDataIsPngFormat(data) || binaryDataIsJpgFormat(data) || binaryDataIsGifFormat(data);
|