我正在使用UIL(由Nosotra)下载服务器渲染的图像,并且服务器最多需要50秒来创建每个图像.服务器的超时设置为15秒,因此我们创建了一个在ImageDownloader.getStream()方法中实现的轮询机制.下载后,图像将显示在ViewPager中(android.support.v4.view.ViewPager就像样本一样).
当用户导航到其他页面时,我希望在不下载文件的情况下停止轮询,但似乎没有" 好 "方法来打破下载流程.
getStream伪代码
1. Parse custom-style URI ("asdf://mypng|123455678945643563245");
2. Make a real world URL from it.
3. Poll the server for the image url (causes the server to render - could take up to 1m30s).
4. Get the stream from the URL, return the stream to caller.
Example Code: InputStream is = (InputStream) url.getContent();
Run Code Online (Sandbox Code Playgroud)
到目前为止尝试了什么
null从我的getStream方法返回会导致NullPointerException抛出,所以它与抛出异常基本相同.
抛出异常时,图像会停止,但是:
OutOfMemoryError,所以我在屏幕上显示错误.我不应该得到错误.我已经尝试过这个SO问题的清单 …我使用UniversalImageLoader(displayImage方法)加载图像
但它抛出NoSuchFieldException异常:
Landroid/widget/ImageView 类中没有字段 mMaxWidth;('android.widget.ImageView' 的声明出现在 /system/framework/framework.jar!classes3.dex 中)
怎么修 ?
我在一个需要获取授权源图像的应用程序中使用通用图像加载器.
到目前为止,我已经使用自己的类扩展了URLConnectionImageDownloader类,并使用我自己的实现方法覆盖了getStreamFromNetwork方法,该实现方法在URLConnection对象中设置了授权标头:
public class authURLConnectionImageDownloader extends URLConnectionImageDownloader {
@Override
public InputStream getStreamFromNetwork(URI imageUri) throws IOException {
String auth = Base64.encodeToString(("username" + ":"+"psswd").getBytes(), Base64.NO_WRAP);
URLConnection conn = imageUri.toURL().openConnection();
conn.setRequestProperty("Authorization", "Basic " + auth);
conn.setConnectTimeout(DEFAULT_HTTP_CONNECT_TIMEOUT);
conn.setReadTimeout(DEFAULT_HTTP_READ_TIMEOUT);
return new FlushedInputStream(new BufferedInputStream(conn.getInputStream(), BUFFER_SIZE));
}
Run Code Online (Sandbox Code Playgroud)
并设置我的ImageLoader ...
imageLoader = ImageLoader.getInstance();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(MainActivity.this)
.imageDownloader(new authURLConnectionImageDownloader())
.build();
imageLoader.init(config);
Run Code Online (Sandbox Code Playgroud)
到目前为止,我无法让它工作.图像未下载.但更重要的是,我在getStreamFromNetwork()中放了一个断点,它永远不会被击中?我究竟做错了什么?
我有一个应用程序远程加载大量的大图像.当我使用nostra的通用图像加载器(https://github.com/nostra13/Android-Universal-Image-Loader)时,我常常会出现Out Of Memory错误.我不知道应该如何设置图像加载器来防止这种情况发生.
这是我目前的ImageLoader规格:
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
.enableLogging()
.memoryCache(new WeakMemoryCache())
.build();
this.imgDispOpts = new DisplayImageOptions.Builder()
.cacheInMemory()
.cacheOnDisc()
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
.build();
this.imageLoader = ImageLoader.getInstance();
this.imageLoader.init(config);
Run Code Online (Sandbox Code Playgroud)
是的,我在调用displayImage()时传递了imgDispOpts.
05-16 10:26:18.267: E/dalvikvm(12692): Could not find class 'com.nostra13.universalimageloader.core.ImageLoaderConfiguration$Builder', referenced from method com.test.app.ApplicationRoot.onCreate
05-16 10:26:18.267: W/dalvikvm(12692): VFY: unable to resolve new-instance 555 (Lcom/nostra13/universalimageloader/core/ImageLoaderConfiguration$Builder;) in Lcom/test/app/ApplicationRoot;
05-16 10:26:18.267: D/dalvikvm(12692): VFY: replacing opcode 0x22 at 0x0005
05-16 10:26:18.267: D/dalvikvm(12692): DexOpt: unable to opt direct call 0x123f at 0x0b in Lcom/test/app/ApplicationRoot;.onCreate
05-16 10:26:18.267: D/AndroidRuntime(12692): Shutting down VM
05-16 10:26:18.267: W/dalvikvm(12692): threadid=1: thread exiting with uncaught exception (group=0x4168f2a0)
05-16 10:26:18.272: E/AndroidRuntime(12692): FATAL EXCEPTION: main
05-16 10:26:18.272: E/AndroidRuntime(12692): java.lang.NoClassDefFoundError: com.nostra13.universalimageloader.core.ImageLoaderConfiguration$Builder
05-16 10:26:18.272: E/AndroidRuntime(12692): at com.test.app.ApplicationRoot.onCreate(ApplicationRoot.java:16)
05-16 …Run Code Online (Sandbox Code Playgroud) Universal Image Loader未在imageLoader.loadImage中应用显示图像选项这是我的代码
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.loading_image_background)
.showImageForEmptyUri(R.drawable.ic_launcher)
.showImageOnFail(R.drawable.loading_image_background)
.cacheInMemory()
.cacheOnDisc()
.bitmapConfig(Bitmap.Config.RGB_565)
.displayer(new RoundedBitmapDisplayer (20))
.build();
ImageSize targetSize = new ImageSize(50, 50);
imageLoader.loadImage(image_poster_url, targetSize, options,
new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri,
View view, Bitmap loadedImage) {
holder.posterImage.setImageBitmap(loadedImage);
}
});
Run Code Online (Sandbox Code Playgroud)
图像重新调整大小并在listview中完美显示.但是显示选项(圆形位图diplayer)不适用于图像.有什么建议?
我想问一下UIL从InputStream输入的URI.因为我的图像来自ZIP,然后我必须提取它来显示该图像.因为图像太大,我必须使用UIL库,任何人都知道如何从InputStream插入UIL.
有没有简单的方法来平铺从ImageView上的URL下载的位图?
最好使用Picasso或UniversalImageLoader.
我正在考虑从毕加索缓存中获取图像并在画布上绘图,但也许有更优雅的方式?
谢谢,Bartek.
我在girdview中使用通用图像加载器.有些视频可以改变图像,有些不起作用并且给出错误,
03-17 12:49:52.287: D/skia(21755): --- SkImageDecoder::Factory returned null
03-17 12:49:52.287: E/ImageLoader(21755): Image can't be decoded [file:////storage/sdcard0/Movies/Naruto Episodes 55.mp4_270x270]
Run Code Online (Sandbox Code Playgroud)
这是我在主类中的代码.
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
.cacheOnDisc(true).cacheInMemory(true)
.imageScaleType(ImageScaleType.EXACTLY)
.displayer(new FadeInBitmapDisplayer(300)).build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
getApplicationContext())
.defaultDisplayImageOptions(defaultOptions)
.memoryCache(new WeakMemoryCache())
.discCacheSize(100 * 1024 * 1024).build();
ImageLoader.getInstance().init(config);
Run Code Online (Sandbox Code Playgroud)
这是adpater中的代码,
String url = "/storage/sdcard0/Movies/Naruto Episodes 55.mp4";
ImageLoader imageLoader = ImageLoader.getInstance();
DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true)
.cacheOnDisc(true).resetViewBeforeLoading(true)
.showImageForEmptyUri(R.drawable.x_document_icon)
.showImageOnFail(R.drawable.x_document_icon)
.showImageOnLoading(R.drawable.x_document_icon).build();
//initialize image view
//download and display image from url
imageLoader.displayImage("file:///"+url, img_btn, options);
Run Code Online (Sandbox Code Playgroud)
以下代码工作正常但需要一些时间.
Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(url, …Run Code Online (Sandbox Code Playgroud) 我需要加载尺寸为2450 x 2450像素的大图像.
Bitmap bitmap = ImageLoader.getInstance().loadImageSync(url,
ImageConfig.getImageOptions());
Run Code Online (Sandbox Code Playgroud)
问题是,在低端设备(内存小于1 GB的手机)上,出现内存不足的情况.
这是我的DisplayImageOptions
public static DisplayImageOptions getImageOptions() {
DisplayImageOptions.Builder options = new DisplayImageOptions.Builder();
options.delayBeforeLoading(10)
//The reason I'm using ARGB_8888 because I need to load bitmap without losing it's quality
.bitmapConfig(Bitmap.Config.ARGB_8888)
.imageScaleType(ImageScaleType.NONE)
//I'm not using disk or memory cache
.cacheOnDisk(false)
.cacheInMemory(false);
return options.build();
}
Run Code Online (Sandbox Code Playgroud)
我尝试根据设备分辨率添加目标大小,但它不起作用,加载的位图仍然具有2450 x 2450像素的尺寸.
int height = orientation == Configuration.ORIENTATION_PORTRAIT ?
displaymetrics.heightPixels : displaymetrics.widthPixels;
Bitmap bitmap = ImageLoader.getInstance().loadImageSync(imageUri,
new ImageSize(height, height), ImageConfig.getImageOptions());
Run Code Online (Sandbox Code Playgroud)
我试图将imageScaleType更改为ImageScaleType.EXACTLY,加载位图大小调整为1225 x 1225像素,在所有设备上,我需要获得高端设备的原始尺寸,并调整低端设备的尺寸.
主要问题是目标尺寸不起作用 …