【问题标题】:how to download images with bad quality?如何下载质量差的图像?
【发布时间】:2016-05-05 01:59:13
【问题描述】:

我有一个带有 imageview 和 textview 的 recyclerview,我想使用质量差的下载来填充以加速下载过程。

imageview 有一个 onclick 方法,它显示一个对话框,其中下载的图像像背景一样,所以,我想下载质量差的图像,只有当用户点击图像时,然后下载高质量的图像。

这是我的下载代码:

try {
     ruta = "http://192.168.1.67/apptequila/fotos/" + usuariojSON + "/" + fotojSON;

    URL url = new URL(ruta);
     HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setConnectTimeout(15000);
    connection.connect();
    InputStream input = connection.getInputStream();
    bitmap = BitmapFactory.decodeStream(input);


     }catch (SocketTimeoutException e){
    cancelarHilo(3);
    } catch (Exception e) {
    Log.i("SMS", "ERROR AL OBTENER FOTO: " + e.toString());
     bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.sin_perfil);
     }
     data.add(new MiModel(nombrejSON, categoriajSON, likesjSON, lemajSON, bitmap, idsjSON,latitudjSON,longitudjSON,distanciajSON));

onclick imageview的代码:

    public void Pressimage(final int position) {
        customDiag = new Dialog(MainActivity.this);
        customDiag.requestWindowFeature(Window.FEATURE_NO_TITLE);
        customDiag.setContentView(R.layout.dialog);




                RelativeLayout relativeLayout = (RelativeLayout)customDiag.findViewById(R.id.root);
                Drawable drawable = new BitmapDrawable(getApplicationContext().getResources(),
                        data.get(position).getImagen());
                if(Build.VERSION.SDK_INT > 16) {
                    relativeLayout.setBackground(drawable);
                }else{
                    relativeLayout.setBackgroundDrawable(drawable);
                }

                customDiag.show();
}

【问题讨论】:

    标签: android image bitmap download httpconnection


    【解决方案1】:

    您为什么要这样做? 使用PicassoVolley,因为它们将允许下载/缓存图像。 它们还可以非常好地在列表视图中显示图像。这将缓解您试图通过使图像看起来“糟糕”来减少内存负担的问题。

    【讨论】:

      猜你喜欢
      • 2017-12-28
      • 1970-01-01
      • 2020-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-09
      相关资源
      最近更新 更多