jcs

使用libjpeg进行图片压缩

偶尔善良 提交于 2020-04-08 17:51:49
简介 由于工作原因,boss下达的任务就大概说了对图片进行压缩寻找比较合理的方式,还举了一个项目中的坑,就是系统原生的Bitmap.compress设置质量参数为100生成图片会变大的坑。所以我打算用一点时间研究研究Bitmap在内存和外存中的情况。首先需要对图片进行压缩,大家都知道图片是Android里面一个大坑,具体的问题有: OOM,一不留神就用OOM来冲冲喜,所以网上就有了很多解决oom问题的建议,但是由于网友的水平不一也导致建议参差不齐。(内存) 图片压缩再加载失真严重,或者压缩率不够达不到项目要求的效果。(外存) 那我今天就要解决的就是通过今天查阅的资料和自己的判断,还有实践归档一下图片在Android上的问题。并且给出自己解决图片压缩问题的解决方案和实际操作。 1、为什么Android上的图片就不如IOS上的? libjpeg是广泛使用的开源JPEG图像库,安卓也依赖libjpeg来压缩图片。但是安卓并不是直接封装的libjpeg,而是基于了另一个叫Skia的开源项目来作为的图像处理引擎。Skia是谷歌自己维护着的一个大而全的引擎,各种图像处理功能均在其中予以实现,并且广泛的应用于谷歌自己和其它公司的产品中(如:Chrome、Firefox、 Android等)。Skia对libjpeg进行了良好的封装,基于这个引擎可以很方便为操作系统、浏览器等开发图像处理功能。

Android中使用libjpeg-turbo进行图片质量压缩过程记录

假装没事ソ 提交于 2020-04-07 21:27:37
项目开发过程中发现Android的质量压缩算法在图片过大,色彩丰富的前提下,压缩的性能不是特别好,经过调查发现Android底层实现使用Skia引擎,封装了了libjpeg图像库。为了适配低版本的Android手机,其内部的压缩算法并没有采用普遍的哈夫曼算法,因为哈夫曼算法比较占CPU,从而选择了其他的算法B,而算法B的效果并没有达到项目预期,所以这里研究一下通过自编译libjpeg来使用哈夫曼算法进行图片压缩的操作。 libjpeg-turbo是针对libjpeg库的一个优化版本,具体的介绍可以移步 官方网站 。接下来记录如何编译出对应的so包文件,这里采用Cmake的方式进行。 首先下载libjpeg-turbo 源码 ,将源码中的所有文件拷贝到cpp文件夹目录下: 这里需要注意的是需要把项目的CmakeList文件改变成libjpeg-turbo文件夹下面的CmakeList文件,然后进行编译,就可以在如下目录中产生so文件了: 第二步是要复制对应的头文件到新项目当中,主要的头文件包括如下几个,当然如果调用时候需要用到其他的头文件,那么在复制进去即可: 然后在CmakeList中增加so库链接,连接到我们项目中的so包中去: cmake_minimum_required(VERSION 3.4.1) set(distribution_DIR ../../../../libs)

JCS notify on expire/remove

南笙酒味 提交于 2020-01-05 10:29:49
问题 we use JCS very simply. Not distributed or anything, simply: JCS jcs = JCS.getInstance("region-name"); I'm trying to register some kind of listener that can be used to receive a notification/event when an element is removed or expired from the cache... I've been digging through the JCS javadoc for awhile now and I've tried: - adding an Implementation of IElementEventHandler to the default ElementAttributes of the cache ... it never gets called. - using the various implementations of

JCS notify on expire/remove

橙三吉。 提交于 2020-01-05 10:28:40
问题 we use JCS very simply. Not distributed or anything, simply: JCS jcs = JCS.getInstance("region-name"); I'm trying to register some kind of listener that can be used to receive a notification/event when an element is removed or expired from the cache... I've been digging through the JCS javadoc for awhile now and I've tried: - adding an Implementation of IElementEventHandler to the default ElementAttributes of the cache ... it never gets called. - using the various implementations of

How to set the auxiliary disk cache programmatically using jcs

Deadly 提交于 2019-12-24 11:28:12
问题 I am obtaining my cache object like this CacheAccess<Object, Object> cache = JCS.getInstance("queries"); I have put a config file in the classpath cache.ccf. For debugging reasons I want to set the aux disk cache path programmatically, but do not know how to obtain the interface I need. I know there exsists an attribute class where one may set this path, but I do not know how to get the instance of this class which refers to the cache I am using. Any ideas? 来源: https://stackoverflow.com

How to change JCS cache.ccf file's path?

孤者浪人 提交于 2019-12-23 07:57:41
问题 I'm trying to change path of cache.ccf file about an hour... When I'm calling JCS.getInstance("myRegion"); I'm getting this error: Exception in thread "main" java.lang.IllegalStateException: Failed to load properties for name [/cache.ccf] I tried to put cache.ccf into src folder. In this case everything's OK. But I want it to be in ./config/ directory, not in ./src . I tried to change config file name: JCS.setConfigFilename("../config/cache.ccf"); But it's not working and I'm getting the same

JCS: How to access cache in two different applications running in same server

送分小仙女□ 提交于 2019-12-13 07:35:18
问题 jcs: I have two applications running in Glassfish. How do I retrieve cache stored in one application to another application 回答1: You could use a shared auxiliary region cache (disk, jdbc, lateral) with the same coordinates (configs). Cache elements from application A will be available on application B when you check it or get it from shared cache. http://commons.apache.org/proper/commons-jcs/JCSPlugins.html 来源: https://stackoverflow.com/questions/27063605/jcs-how-to-access-cache-in-two

Cache memory not saving values in cache when running the project

牧云@^-^@ 提交于 2019-12-11 16:12:33
问题 I am implementing cache system in maven project.I am not using spring or any framework.The concept is to : 1.At first user will hit the API and Check whether the data is available in cache or not. 2.If cache is empty ,call the database and put values in cache and send them back. 3.If cache is not empty, then return the values from cache. So,for proper organization,I used the Java caching System(JCS) library,which I took reference from: https://www.javaworld.com/article/2077936/open-source

JCS edit Disk Auxiliary Cache DiskPath

这一生的挚爱 提交于 2019-12-10 14:00:25
问题 I am developping a web app with JCS 1.3 caching. I need to edit the DiskPath of the Indexed Disk Auxiliary Cache at runtime from a JVM property. Do you know a way to do this ? I managed to create the AuxiliaryCache object but I don't know how to connect it with all my regions defined in cache.ccf. Here is the code creating the disk cache : IndexedDiskCacheAttributes indexedCacheAttr = new IndexedDiskCacheAttributes(); indexedCacheAttr.setMaxKeySize(10000); indexedCacheAttr

How do you share Java Caching System (JCS) resource across multiple EJB

痴心易碎 提交于 2019-12-06 06:42:06
问题 I am using JCS to store the ldap search results which should be shared by multiple EJB. I have created a singleton class to initialize JCS only once but due to EJB's classloader, it's been initialized multiple times with its own copy. so search resources are not shared. How are you guys resolving issue where you need to share the cache across multiple beans? I am looking for cache within JVM. (Not the remote e.g memcached etc.). Glassfish is used as an application server. 回答1: I haven't been