EPImageUtil.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package epson.print;
  2. import android.graphics.Bitmap;
  3. import android.graphics.Matrix;
  4. import android.media.ExifInterface;
  5. import java.io.IOException;
  6. public class EPImageUtil {
  7. public static final String CANCEL_FILE_BASE_NAME = "cancel.dat";
  8. public static final int RETURN_CODE_CANCLE = -257;
  9. public static native int jpegTo1BitBmpPixelRoundDown(String str, String str2, int i);
  10. public native int bmp2jpg(String str, String str2, int i);
  11. public native int color2grayscale(String str, String str2);
  12. public native int getBitCount(String str);
  13. public native int jpg2bmp(String str, String str2, int i);
  14. public native int resizeImage(String str, String str2, int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9, int i10);
  15. public native int rotate180Image(String str, String str2);
  16. public native int rotateR270Image(String str, String str2);
  17. public native int rotateR90Image(String str, String str2);
  18. public native int tiff2bmp(String str, String str2);
  19. public native int writeDate(String str, String str2, int i, int i2);
  20. static {
  21. try {
  22. System.loadLibrary("epsimage");
  23. } catch (Exception e) {
  24. e.printStackTrace();
  25. }
  26. }
  27. public int rotateImage(String str, String str2, int i) {
  28. if (i == 90) {
  29. return rotateR90Image(str, str2);
  30. }
  31. if (i == 180) {
  32. return rotate180Image(str, str2);
  33. }
  34. if (i != 270) {
  35. return 0;
  36. }
  37. return rotateR270Image(str, str2);
  38. }
  39. public Bitmap check_rotate(String str, Bitmap bitmap) {
  40. try {
  41. int attributeInt = new ExifInterface(str).getAttributeInt(android.support.media.ExifInterface.TAG_ORIENTATION, 0);
  42. if (attributeInt != 6 && attributeInt != 3 && attributeInt != 8) {
  43. return bitmap;
  44. }
  45. Matrix matrix = new Matrix();
  46. if (attributeInt == 3) {
  47. matrix.setRotate(180.0f);
  48. } else if (attributeInt == 6) {
  49. matrix.setRotate(90.0f);
  50. } else if (attributeInt != 8) {
  51. matrix.setRotate(0.0f);
  52. } else {
  53. matrix.setRotate(270.0f);
  54. }
  55. return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false);
  56. } catch (IOException e) {
  57. e.printStackTrace();
  58. return bitmap;
  59. }
  60. }
  61. }