Android的远程图像获取的问题? [英] android Remote image Getting problem?

查看:112
本文介绍了Android的远程图像获取的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code,以显示与下一个和previous按钮遥感图像。 点击next和previous按钮两次或三次不显示图片下一张图片。 和DisplayLiveImage的位图是空。

i am using following code to display remote image with next and previous buttons. clicking on next and previous buttons two or three times it does not show image next image. and bitmap of DisplayLiveImage is null.

任何一个可以检查这个缓冲区的问题?或连接?

can any one check is this a buffer problem? or connection?

ImageView img;
     int CurrentImageIndex;


    protected void onCreate(Bundle savedInstanceState)
    {  

        super.onCreate(savedInstanceState);
        setContentView(R.layout.imageviwer);
        setTitle("some text");



        myRemoteImages = new String[6];
        myRemoteImages[0]="http://www.comparecheapinsurance.com/car-insurance/images/car-insurance-policy.jpg";
        myRemoteImages[1]="http://www.speedace.info/solar_cars/solar_car_images/auburn_university_solar_car_banked_road_test.jpg";
        myRemoteImages[2]="http://zedomax.com/blog/wp-content/uploads/2009/07/car.jpg";
        myRemoteImages[3]="http://www.wallpaperez.net/wallpaper/car/Lamborghini-prototype-car-926.jpg";
        myRemoteImages[4]="http://www.evbeat.com/blog/wp-content/uploads/2009/03/aptera-electric-car.jpg";
        myRemoteImages[5]="http://www.cartuningcentral.com/wp-content/uploads/2008/01/exotic-car-pagani-zonda.jpg";


        CurrentImageIndex= 0;

        img= (ImageView)findViewById(R.id.myImageView);
        DisplayLiveImage(CurrentImageIndex);

        Button previous = (Button)findViewById(R.id.btnPrevious);
        Button next = (Button)findViewById(R.id.btnNext);


        next.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {

                ShowNext();

            }

        });

        previous.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {

                ShowPrevious();

            }

        });

    }


    public void DisplayLiveImage(int val)
    {

                     try {  

                             URL aURL = new URL(myRemoteImages[val]);  
                             URLConnection conn = aURL.openConnection();  
                             conn.connect();  
                             InputStream is = conn.getInputStream();  

                             BufferedInputStream bis = new BufferedInputStream(is);  

                             Bitmap bm = BitmapFactory.decodeStream(bis);  
                             bis.close();  
                             is.close();  

                            // i.setImageBitmap(bm); 
                             img.setImageBitmap(bm);
                        } catch (IOException e) {  

                        }  


                  //   i.setScaleType(ImageView.ScaleType.FIT_CENTER);  

                   //  i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));  
                    // return i;


    }






    public void ShowNext()
    {
        if(CurrentImageIndex < myRemoteImages.length )
        {
            CurrentImageIndex  = CurrentImageIndex +1 ;
            DisplayLiveImage(CurrentImageIndex);
        }

    }


    public void ShowPrevious()
    {

        if(CurrentImageIndex > 0 )
        {
            CurrentImageIndex  = CurrentImageIndex -1 ;
            DisplayLiveImage(CurrentImageIndex);
        }



    }

任何帮助将appriciated。

any help would be appriciated.

推荐答案

该问题可能与您试图下载图像的分辨率/大小和你的图像视图设置。

The problem maybe with the resolution/size of images you are trying to download and set in your image view.

在这个网址的图片

http://www.wallpaperez.net/wallpaper/车/兰博基尼原型车 - 926.jpg

是1920 * 1200像素的也许只是过大的模拟器。在code工作正常进行的其他较小的图片。

is 1920*1200 pixels which maybe just too big for the emulator. The code is working fine for other smaller pictures.

这篇关于Android的远程图像获取的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆