1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package epson.print.Util;
- import android.graphics.BitmapFactory;
- import epson.print.CommonDefine;
- public class ImageFormatIdentifier {
- public static final int FILE_FORMAT_BMP = 1;
- public static final int FILE_FORMAT_JPEG = 3;
- public static final int FILE_FORMAT_PNG = 2;
- public static final int FILE_FORMAT_UNKNOWN = 0;
- public static int identifyImageFormat(String str) {
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeFile(str, options);
- int mimeTypeToInt = mimeTypeToInt(options);
- if (mimeTypeToInt != 0) {
- return mimeTypeToInt;
- }
- return localIdentifyImageFormat(str);
- }
- public static int mimeTypeToInt(BitmapFactory.Options options) {
- if (options == null || options.outMimeType == null) {
- return 0;
- }
- String str = options.outMimeType;
- if (CommonDefine.IMAGE_TYPE_BMP.equalsIgnoreCase(str)) {
- return 1;
- }
- if ("image/png".equalsIgnoreCase(str)) {
- return 2;
- }
- if ("image/jpeg".equalsIgnoreCase(str)) {
- return 3;
- }
- return 0;
- }
- public static int localIdentifyImageFormat(String str) {
- return new BmpFileInfo().readParams(str) ? 1 : 0;
- }
- }
|