我有一个查询不特定于 UniversalImageLoader ,但是因为我正在尝试使用内容流加载我面临的以下问题的图像.
我正在使用输入流"stream://"来使用ImageLoader.一切正常,除了针对同一请求的输入流的哈希码生成方式不同之外,因此迫使图像加载器再次从网络而不是从磁盘下载图像.
我该怎么做才能解决它.
PS:我尝试遵循这里
获取InputStream的代码是(UtilityMethod只是一个异步任务):
public void displayContentImage(final String fileId, final ImageView imageView) { UtilityMethods.startMyTask(new AsyncTask<Object, Void, InputStream>() { @Override protected InputStream doInBackground(Object... params) { CMServiceGateway cmServiceGateway = new CMServiceGateway(); final InputStream inputStream = cmServiceGateway.GetContentAsStream(fileId); if (inputStream != null) { //String imageId = "stream://" + inputStream.hashCode(); //Log.d("ImageId :: 1 ::", "file id : " + fileId + "hashcode: " + imageId); //String imageId2 = "stream://" + cmServiceGateway.GetContentAsStream(fileId).hashCode(); //Log.d("ImageId :: 2 ::", "file id : " + fileId + "hashcode: " + imageId2); return inputStream; } return null; } @Override protected void onPostExecute(InputStream inputStream) { if (inputStream != null) { displayImage(inputStream, imageView); } } }); }解决方案
哈希码的基本问题与上面的示例相同,在该示例中,即使inputStream对象是第二个日志哈希码也不同于第一个日志哈希码使用的是相同的.
//String imageId = "stream://" + inputStream.hashCode(); //Log.d("ImageId :: 1 ::", "file id : " + fileId + "hashcode: " + imageId); //String imageId2 = "stream://" + cmServiceGateway.GetContentAsStream(fileId).hashCode(); //Log.d("ImageId :: 2 ::", "file id : " + fileId + "hashcode: " + imageId2);尽管不能完全回答上述问题,但是我能够通过不将哈希码作为id传递给通用图像加载器来解决此问题.相反,我通过了唯一的文件ID,现在可以很好地显示来自内存缓存的图像.
I have a query not particular to UniversalImageLoader but because i am trying to use the content stream to load the image i am facing following issue.
I am using input stream "stream://" to be able to use ImageLoader. Everything is working fine except that the hashcode of the input stream for the same request is generated differently and hence forces the imageloader to download the image again from the network instead of the disk.
What should i do to fix it.
PS: I tried to follow the answer from here
The code to get InputStream is (The UtilityMethod is noting just an async task):
public void displayContentImage(final String fileId, final ImageView imageView) { UtilityMethods.startMyTask(new AsyncTask<Object, Void, InputStream>() { @Override protected InputStream doInBackground(Object... params) { CMServiceGateway cmServiceGateway = new CMServiceGateway(); final InputStream inputStream = cmServiceGateway.GetContentAsStream(fileId); if (inputStream != null) { //String imageId = "stream://" + inputStream.hashCode(); //Log.d("ImageId :: 1 ::", "file id : " + fileId + "hashcode: " + imageId); //String imageId2 = "stream://" + cmServiceGateway.GetContentAsStream(fileId).hashCode(); //Log.d("ImageId :: 2 ::", "file id : " + fileId + "hashcode: " + imageId2); return inputStream; } return null; } @Override protected void onPostExecute(InputStream inputStream) { if (inputStream != null) { displayImage(inputStream, imageView); } } }); }解决方案
The basic problem of hash code equal like the sample above where you will find that the second log hash code is different than first log hash code even if the inputStream object used is same.
//String imageId = "stream://" + inputStream.hashCode(); //Log.d("ImageId :: 1 ::", "file id : " + fileId + "hashcode: " + imageId); //String imageId2 = "stream://" + cmServiceGateway.GetContentAsStream(fileId).hashCode(); //Log.d("ImageId :: 2 ::", "file id : " + fileId + "hashcode: " + imageId2);Although not answering the above question exactly but I am able to resolve this problem by not passing the hashcode to the universal image loader as id. Instead i passed the unique file Id's and it worked well now to display image from memory cache.
更多推荐
即使请求相同,Java InputSream的hascode也会每次都不同
发布评论