标签: networkimageview

显示没有网络请求的NetworkImageView的默认图像

我有一个ListView显示的东西,其中许多有一个说明性的图像,其中一些没有.ViewHolder使用NetworkImageView显示插图.

问题是即使设置了默认图像,也只有在调用setImageUrl()时才会显示它,如果url为空,则会将视图的源位图设置为null.如果网址不为空,则会发出请求.这意味着即使没有与该特定视图关联的有效网络URL,也强制一个人发出网络请求,否则不显示默认图像而是显示空视图.

(提交的问题:https://code.google.com/p/android/issues/detail?id = 59538)

有没有办法对没有有效网址的项目进行虚假网络请求?

android android-volley networkimageview

13
推荐指数
1
解决办法
1万
查看次数

try/catch 不适用于网络图像(例外:图像数据无效)

我已经获取网络图像并使用三元运算符,我可以在其中显示网络图像,但无法显示默认资产图像,其中网络图像在网格中默认图像无效,也如此-

\n

我是颤振新手

\n
 image: NetworkImage(products[index]\n                                              .productImageList[0]\n                                  )!= null\n                                      ? NetworkImage(\n                                      products[index].productImageList[0])\n                                      :Image.asset("assets/defimg.jpg"),\n                                  fit: BoxFit.fitHeight ),\n
Run Code Online (Sandbox Code Playgroud)\n

它在索引 0 上显示网络图像,但不会加载网络图像无效或为空的资产图像并抛出此错误 -

\n
\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90 Exception caught by image resource service \xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nThe following _Exception was thrown resolving an image codec:\nException: Invalid image data\n\nWhen the exception was thrown, this was the stack: \n#0      _futurize (dart:ui/painting.dart:5230:5)\n#1      ImageDescriptor.encoded (dart:ui/painting.dart:5098:12)\n#2      instantiateImageCodec (dart:ui/painting.dart:1998:60)\n<asynchronous suspension>\n
Run Code Online (Sandbox Code Playgroud)\n

之后我尝试了 try/catch -我的 try catch 代码是 --

\n
child: Builder(builder: (BuildContext context) {\n                              try {\n                                return Center(\n                                  child: Image.network(\n                                      products[index]\n …
Run Code Online (Sandbox Code Playgroud)

try-catch conditional-operator networkimageview flutter-dependencies flutter-layout

10
推荐指数
1
解决办法
3万
查看次数

一次渲染大量图像时 Flutter 应用程序崩溃问题

我想讨论我在 flutter 应用程序中遇到的问题。该应用程序是一款社交电子商务应用程序,其布局类似于 Facebook 或 Instagram。我正在使用 10 个帖子的分页,每个帖子最多包含 4 个图像,就像网格视图一样。当我滚动到 5-8 页时,由于渲染大量图像,应用程序崩溃。

我尝试了很多解决方案,但没有解决这个问题。以下是我迄今为止尝试过的一些解决方案的列表。

  1. 尝试了cached_network_image插件。应用程序在滚动最多 50-60 个帖子或估计最多 200 个图像时崩溃。

  2. 尝试了optimized_cached_image。崩溃率被最小化了一点,我能够滚动最多 250-300 张图像,然后应用程序再次崩溃。

  3. 尝试了 FadeInImage.network 和 FadeInImage.memoery 小部件,但当滚动到 100 张图像时应用程序也会崩溃。

  4. 将图像下载到本地目录,然后尝试使用 Image.memory 和 Image.file 小部件显示图像。但这个解决方案也不起作用。

你能建议我任何解决方案来解决这个问题吗

crash image dart networkimageview flutter

10
推荐指数
1
解决办法
3300
查看次数

如何修复 Flutter 中的像素化图像

我想创建一个圆形图像小部件,但它最终会像素化。

有了Image.network(url),我得到以下信息:

像素化图像

而原来的样子是这样的:

在此输入图像描述

这是相关代码:

class RoundedImage extends StatelessWidget {
  final String URL;
  final double size;
  final bool dynamicallySized;
  final double borderRadius;
  final bool onlyTopBorderRadius;

  const RoundedImage({
    @required this.size,
    @required this.url,
    this.dynamicallySized = false,
    this.borderRadius = 8.0,
    this.onlyTopBorderRadius = false,
  });

  @override
  Widget build(BuildContext context) {
    final newSize = dynamicallySized ? PaddingUtils.getPadding(context, padding: size) : size;
    return ClipRRect(
      borderRadius:
          onlyTopBorderRadius ? BorderRadius.vertical(top: Radius.circular(borderRadius)) : BorderRadius.circular(borderRadius),
      child: CachedNetworkImage(
        imageUrl: url,
        height: newSize,
        width: newSize,
        fit: BoxFit.cover,
      ),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

image dart networkimageview flutter

8
推荐指数
1
解决办法
3858
查看次数

使用NetworkImageView(Volley库)时的OOM

背景

使用Volley库NetworkImageView是处理从Web显示图像的便捷方式.

但是,它有一些错误(正如我在这里写的).

问题

使用它可以获得的一个问题是它不能以内存有效的方式解码来自Web的图像.

这意味着,如果您使用的是多NetworkImageView一个gridview,每个显示,有一个未知的分辨率(可能是小的,可能是大)的图像,你会最终有一个OOM.

作为一个例子,你可以把这个对象的URL是这一个,看看自己的应用中展示的位图,相比之前使用了多少后使用的内存.

这个问题

如何修改NetworkImageView解码位图的方式?

我可以改变它的一种方法是使在使用它下调到所需要的尺寸(或至少设置它的最大屏幕尺寸),例如,它解码位图这个方法缩小的.

android bitmap out-of-memory android-volley networkimageview

7
推荐指数
1
解决办法
6296
查看次数

在Volley中向NetworkImageView添加身份验证标头

我使用Volley和NetworkImageView.这对几个项目来说非常有用.但是我现在需要在标题中为我的图像请求发送auth令牌.做这个的最好方式是什么?在我的正常请求中,我覆盖getHeaders()并以这种方式放置我的令牌.但ImageLoView使用的ImageLoader会生成一个通用的Request,这使得很难添加标题......

authentication android android-volley networkimageview

7
推荐指数
2
解决办法
2666
查看次数

如何使用volley库android创建圆角图像

我从服务器获取方形的图像网址我必须使它成为圆角图像.实际上我正在使用排球库,我知道如何使用通用图像加载器和毕加索库创建圆角图像.在排球库我设置图像在网络imageview像setimageUrl请帮助我

 holder.ivImage.setImageUrl(url, imageLoader);
Run Code Online (Sandbox Code Playgroud)

android android-volley networkimageview

7
推荐指数
3
解决办法
9745
查看次数

让Volley的NetworkImageView显示本地图像文件

NetworkImageView 用来显示从远程URL下载的一些封面,我成功地设法缓存并显示它们,但我想让用户设置自己的封面图像,如果他们想要的话.我尝试使用setImageUrl带有Uri.fromFile(mCoverFile).toString()as参数的方法,但它不起作用.由于它是远程和本地图像的混合,我无法切换到常规ImageViews,所以我想知道是否有任何方法可以启用加载本地图像.

我当然知道的ImageViewsetImageBitmap方法,但NetworkImageView会自动调整创建Bitmap,也防止View回收的GridViewS和ListView秒.

更新: njzk2的答案奏效了.要根据您的View大小自动调整位图,只需ImageRequest.doParse从Volley的源代码中复制该方法.

android android-volley networkimageview

6
推荐指数
1
解决办法
1万
查看次数

尝试调用虚方法'int java.lang.String.hashCode()'

我正在尝试使用Volley Library将URL中的图像加载到girdview中.为此,我正在学习教程.当我运行我的项目时,它从服务器数据库收集所有URL,然后存储在arraylist中.但是不显示图像.我收到了java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference错误.它甚至没有指向我遇到此错误的任何代码行数.见下面Logcat输出:

java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference
        at com.android.volley.Request.<init>(Request.java:136)
        at com.android.volley.toolbox.ImageRequest.<init>(ImageRequest.java:71)
        at com.android.volley.toolbox.ImageLoader.get(ImageLoader.java:219)
        at com.android.volley.toolbox.ImageLoader.get(ImageLoader.java:171)
        at com.android.volley.toolbox.NetworkImageView.loadImageIfNecessary(NetworkImageView.java:141)
        at com.android.volley.toolbox.NetworkImageView.onLayout(NetworkImageView.java:190)
        at android.view.View.layout(View.java:15596)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
        at android.view.View.layout(View.java:15596)
        at android.view.ViewGroup.layout(ViewGroup.java:4966)
        at android.widget.GridView.setupChild(GridView.java:1542)
        at android.widget.GridView.makeAndAddView(GridView.java:1436)
        at android.widget.GridView.makeRow(GridView.java:361)
        at android.widget.GridView.fillDown(GridView.java:302)
        at android.widget.GridView.fillFromTop(GridView.java:437)
        at android.widget.GridView.layoutChildren(GridView.java:1276)
        at android.widget.AbsListView.onLayout(AbsListView.java:2148)
        at android.view.View.layout(View.java:15596)
        at android.view.ViewGroup.layout(ViewGroup.java:4966)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
        at android.view.View.layout(View.java:15596)
        at …
Run Code Online (Sandbox Code Playgroud)

android gridview android-logcat android-volley networkimageview

6
推荐指数
3
解决办法
1万
查看次数

networkimageview以离线模式显示图像?杀死申请后重新开放.就像facebook应用程序一样

我提到了android开发者网站,并用singleton类创建了凌空NetworkImageView.但它不会在应用程序强制关闭后维护缓存图像,并再次在离线状态下打开我的应用程序.如何使网络图像视图在脱机模式下从缓存中获取图像.我正在使用LruCache.

注意:我在整个应用程序中使用NetworkImageView.我在某处读到只有当图像URL包含缓存头时才会存储磁盘缓存.我想了解这一点,如果URL中没有标题,那么如何强制凌空存储图像的磁盘缓存?

我的代码:

public class VolleySingletonPattern {

private static VolleySingletonPattern mInstance;
private RequestQueue mRequestQueue;
private ImageLoader mImageLoader;
private static Context mCtx;

private VolleySingletonPattern(Context context) {
    mCtx = context;
    mRequestQueue = getRequestQueue();

    mImageLoader = new ImageLoader(mRequestQueue, new LruBitmapCache(
            LruBitmapCache.getCacheSize(mCtx)));
}

public static synchronized VolleySingletonPattern getInstance(Context context) {
    if (mInstance == null) {
        mInstance = new VolleySingletonPattern(context);
    }
    return mInstance;
}

public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        // getApplicationContext() is key, it keeps you from leaking the
        // Activity …
Run Code Online (Sandbox Code Playgroud)

android android-volley networkimageview

6
推荐指数
1
解决办法
756
查看次数