如何在Android中使用G4压缩将JPEG图像转换为TIFF格式?

时间:2015-07-29 15:35:40

标签: java android compression tiff

我正在开发一个Android应用程序,我希望能够将我拍摄的相机图片转换成4组压缩效果。

我尝试使用this Android-ImageMagick library,但收到以下错误:

  

java.lang.UnsatisfiedLinkError - NDK

我提到this StackOverflow question要解决,但它没有用。

库的代码出错,Magick.java:43行是init()的调用;方法。 由于我们在Android Studio中使用Gradle,因此我强烈怀疑这是因为Gradle。图书馆作者“如何使用它”的解释是基于没有Gradle的项目。 如果我们将方法“init()”的名称更改为“test()”之类的另一个名称,则会在其他本机方法中发生错误。 我们的项目结构:
并将“ndk.dir”添加到local.properties中,尝试添加“sourceSets":

{
        main {
            jni.srcDirs=['jniLibs']
        }
    }
    ” at build.gradle.

    /**
     * The sole purchase of this class is to cause the native
     * library to be loaded whenever a concrete class is used
     * and provide utility methods.
     *
     * @author Eric Yeo
     * @author Max Kollegov <virtual_max@geocities.com>
     */
    public class Magick {

        static {
            /*String clprop = System.getProperty("jmagick.systemclassloader");
            if (clprop == null || clprop.equalsIgnoreCase("yes")) {
                try {
                    ClassLoader.getSystemClassLoader()
                        .loadClass("magick.MagickLoader").newInstance();
                }
                catch(ClassN`enter code here`otFoundException e) {
                    throw new RuntimeException("Can't load MagickLoader " +
                                               "(class not found)");
                }
                catch(IllegalAccessException e) {
                    throw new RuntimeException("Access to SystemClassLoader "+
                                               "denied (IllegalAccessException)");
                }
                catch(InstantiationException e) {
                    throw new RuntimeException("Can't instantiate MagicLoader " +
                                               "(InstantiationException)");
                }
            }
            else {
                System.loadLibrary("JMagick");
            }*/

            System.loadLibrary("imagemagick");

            init();
        }


        /**
         * Initializes the ImageMagic system
         */
        private static native void init();


        /**
         * Parses a geometry specification and returns the
         * width, height, x, and y values in the rectangle.
         * It also returns flags that indicates which of the
         * four values (width, height, xoffset, yoffset) were
         * located in the string, and whether the x and y values
         * are negative.  In addition, there are flags to report
         * any meta characters (%, !, <, and >).
         * @param geometry String containing the geometry specifications
         * @param rect The rectangle of values x, y, width and height
         * @return bitmask indicating the values in the geometry string
         * @see magick.GeometryFlags
         */
        public static native int parseImageGeometry(String geometry, Rectangle rect);

    }

这是我得到的错误:

java.lang.UnsatisfiedLinkError: Native method not found: com.test.comp.magick.Magick.init:()V
            at com.test.comp.magick.Magick.init(Native Method)
            at com.test.comp.magick.Magick.<clinit>(Magick.java:43)
            at com.test.comp.magick.util.MagickBitmap.fromBitmap(MagickBitmap.java:41)
            at com.test.comp.activity.MainActivity.convertAndSendImage(MainActivity.java:60)
            at com.test.comp.activity.MainActivity.onActivityResult(MainActivity.java:84)
            at android.app.Activity.dispatchActivityResult(Activity.java:5423)
            at android.app.ActivityThread.deliverResults(ActivityThread.java:3347)
            at android.app.ActivityThread.handleSendResult(ActivityThread.java:3394)
            at android.app.ActivityThread.access$1300(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

如果没有在apk中安装ImageMagick库并导致链接错误,则会引发UnsatisfiedLinkError:

您的图书馆必须位于目录/project/libs/armeabi/

相关问题