BmpFileSize.java 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package epson.print.Util;
  2. import android.annotation.TargetApi;
  3. import android.os.Build;
  4. import android.os.StatFs;
  5. public class BmpFileSize {
  6. public static boolean check24BitBmpCapacity(String str, String str2) {
  7. int i = get24BitBmpSize(str);
  8. if (i <= 0) {
  9. return false;
  10. }
  11. try {
  12. return checkDiskCapacity(str2, i);
  13. } catch (Exception unused) {
  14. return false;
  15. }
  16. }
  17. private static int get24BitBmpSize(String str) {
  18. BmpFileInfo bmpFileInfo = new BmpFileInfo();
  19. if (!bmpFileInfo.readParams(str)) {
  20. return -1;
  21. }
  22. return (bmpFileInfo.getWidth() * bmpFileInfo.getHeight() * 3) + 138;
  23. }
  24. public static boolean checkDiskCapacity(String str, int i) {
  25. StatFs statFs = new StatFs(str);
  26. if (Build.VERSION.SDK_INT >= 18) {
  27. return checkDiskCapacityApi18OrMore(statFs, i);
  28. }
  29. return checkDiskCapacityApiLessThan18(statFs, i);
  30. }
  31. @TargetApi(18)
  32. private static boolean checkDiskCapacityApi18OrMore(StatFs statFs, int i) {
  33. return statFs.getFreeBlocksLong() >= (((long) i) / statFs.getBlockSizeLong()) + 1;
  34. }
  35. private static boolean checkDiskCapacityApiLessThan18(StatFs statFs, int i) {
  36. if (statFs.getFreeBlocks() < (i / statFs.getBlockSize()) + 1) {
  37. return false;
  38. }
  39. return true;
  40. }
  41. }