简体   繁体   English

从网址下载的图片未显示在视图中

[英]downloaded image from url is not showing in view

i want to ask that i am downloading images from url means i had url in string array and on button click i move to next url and downloaded image from server. 我想问一下我要从url下载图像,就是说我在字符串数组中有url,然后单击按钮,我移到下一个url,然后从服务器下载图像。 it runs perfectly on samsung galaxy s2 mobile and image downloading and displaying in view but in some other mobile of small size screen it is not displaying in view but in some it displaying ...what is the reason behind this what is happening ..i use setimageBitmap() in onpostExecute() and it work well for samsung galaxys2 what about for lower range mobile why it is not displaying ..i also change the image view height and width but not solve..but some time it is displaying.. 它可以在三星银河s2手机和图像下载并在视图中完美运行,但是在其他一些小尺寸屏幕的手机中,它却不在视图中显示,但在某些情况下却显示...这是什么原因呢?在onpostExecute()中使用setimageBitmap(),它对于三星galaxys2效果很好,为什么在较低范围的移动设备上它不显示..i也会更改图像视图的高度和宽度,但不能解决..但是会显示一段时间。

my code is below.. 我的代码如下。

log cat: 日志猫:

  logcat out  put :



   DEBUG/skia(231): --- decoder->decode returned false
  INFO/System.out(231): Bitmap :: null
  INFO/System.out(231): Bitmap on post :: null
 WARN/InputManagerService(63): Window already focused, ignoring focus gain of:   com.android.internal.view.IInputMethodClient$Stub$Proxy@44c17828
INFO/System.out(231): Message sent
 INFO/image url/////(231):   http://www.artealdiaonline.com/var/artealdia_com/storage/images/argentina/agenda/exposiciones_muestras/carlos_cruz-diez/carlos_cruz-diez2/507989-1-esl-AR/Carlos_Cruz-Diez.jpg
   INFO/System.out(231): Bitmap :: android.graphics.Bitmap@44d64750
     INFO/System.out(231): Bitmap on post :: android.graphics.Bitmap@44d64750

try this for fetching Image :: 试试这个来获取图像::

 ImageButton   tran_btn_skip = (ImageButton) findViewById(R.id.tran_btn_skip);

        try {
            Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(
                    "http://www.hermann-uwe.de/files/images/blue_flower.preview_0.jpg")
                    .getContent());
            tran_btn_skip.setImageBitmap(bitmap);
        } catch (Exception e) {
        }

manifest permission: 清单许可:

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

and try this in mobile device ( not in emulator )if you load from your server but, if you load from any another server ten you can show in emulator. 如果从服务器加载,请在移动设备( not in emulator )中尝试此操作,但是,如果从其他任何服务器加载,则可以在模拟器中显示十。

Update:: 更新::

看到

package com.progressbar;

import java.io.InputStream;
import java.net.URL;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageButton;
public class progressbar extends Activity  {


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ImageButton   tran_btn_skip = (ImageButton) findViewById(R.id.login);

        try {
            Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(
                    "http://www.artealdiaonline.com/var/artealdia_com/storage/images/argentina/agenda/exposiciones_muestras/leila_tschopp3/baja-leila_tschopp_-_river_-acrilico_sobre_tela-130x150_cm_-_2011/498599-1-esl-AR/BAJA-Leila_Tschopp_-_River_-acrilico_sobre_tela-130x150_cm_-_2011.jpg")
                    .getContent());
            tran_btn_skip.setImageBitmap(bitmap);
        } catch (Exception e) {
        }

    }
    }

Try this one: 试试这个:

   HttpURLConnection conn = (HttpURLConnection) url.openConnection();
   conn.setDoInput(true);
   conn.setConnectTimeout(7000);
   conn.connect();
   BufferedInputStream is = new BufferedInputStream(conn.getInputStream());
   Drawable drawable = Drawable.createFromStream(is, imageUrl);
   view.setImageBitmap(drawable)

Here is the complete code: 这是完整的代码:

String imageUrl = "http://someurl.com/example.png";
URL url = new URL(imageUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setConnectTimeout(7000);
conn.connect();
BufferedInputStream is = new BufferedInputStream(conn.getInputStream());
Drawable imageDrawable = Drawable.createFromStream(is, imageUrl);
view.setImageBitmap(imageDrawable);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在图像视图中显示来自URL的图像是否显示模糊(不清晰)的图像? - Showing Image from URL in the image view is showing blurred(not clear) image? 我将图像附加到正在从服务器下载的回收器视图中,但是回收器视图未显示任何图像 - I am attaching a image to a recycler view which is being downloaded from server, but recycler view is not showing any image 显示进度条,直到从服务器下载图像 - showing progressbar until image downloaded from server 在 Flutter - 如何传递从 url 下载的图像 - In Flutter - How to pass the image downloaded from the url Android 显示图库中的图像,需要从 Internet 下载 - Android showing Image in Gallery which needs to be downloaded from Internet 下载的图像未显示在画廊 android - downloaded image not showing in galllery android 为什么我的图片无法从android中的URL下载? - Why is my Image not getting downloaded from the URL in android? (Android应用)尝试将AlertDialog .setIcon()设置为从URL下载的图像 - (Android App) Trying to set AlertDialog .setIcon() as an image downloaded from URL Android - 将下载的图像从 URL 保存到 SD 卡上 - Android - Saving a downloaded image from URL onto SD card 图片网址以.Zip格式下载 - Image URL is downloaded as .Zip format
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM