【问题标题】:Load image from internal memory and display it从内部存储器加载图像并显示
【发布时间】:2017-05-21 00:14:49
【问题描述】:

你好我正在开发一个安卓应用程序,我在安卓设备的内存中保存了几个图像文件。如何在应用中显示它们。

图片在目录/storage/emulated/0/images_to_display

我正在使用 JavaScript。我想显示该特定文件夹中的这些图像。

此外,如果每次我进入应用程序的那个部分时,应用程序中显示的那些图像都会更新(使用较新的图像)(图像通过另一个操作在设备内存中更新,图像文件名不会更改)

感谢任何帮助。

山姆

【问题讨论】:

    标签: javascript android image file cordova


    【解决方案1】:

    找到解决办法:

    添加插件:cordova-plugin-file

    在设备就绪回调上添加: window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);

    <body> 中添加:<img src="/storage/emulated/0/path-to-file/img.png">

    【讨论】:

    • 还在config.xml文件中添加权限:<preference name="AndroidPersistentFileLocation" value="Compatibility" />
    【解决方案2】:
          first compile   in gradle
      compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
    

    然后

     ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
                    .threadPriority(Thread.NORM_PRIORITY - 2)
                    .denyCacheImageMultipleSizesInMemory()
                    .diskCacheFileNameGenerator(new Md5FileNameGenerator())
                    .tasksProcessingOrder(QueueProcessingType.LIFO)
                    .build();
            ImageLoader.getInstance().init(config);
    
      ImageLoader.getInstance().displayImage("file://" + "/storage/emulated/0/images_to_display");
    

    【讨论】:

    • 我正在使用 Javascript 。如何将其转换为 javascript?
    【解决方案3】:

    由于您没有提供有关您使用哪种应用(Cordova、ReactNative 等)的任何信息,因此很难回答。

    对于科尔多瓦,也许你可以看看https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/

    【讨论】:

    • 我正在使用cordova。
    • Yaroslav,你能告诉我怎么做吗?我正在使用科尔多瓦,这就是我想要的。阅读文件让我很困惑。你能帮我一下吗
    • 不幸的是,没有。我记得用它来操作文件,但是我接触 Cordova 已经快一年了。
    猜你喜欢
    • 2015-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-01
    相关资源
    最近更新 更多