Android的远程图像获取的问题?图像、问题、Android

由网友(salted fish(咸鱼))分享简介:我用下面的code,以显示与下一个和previous按钮遥感图像。点击next和previous按钮两次或三次不显示图片下一张图片。和DisplayLiveImage的位图是空。i am using following code to display remote image with next and prev...

我用下面的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]="https://p.xsw88.cn/allimgs/daicuo/20230904/7719.png.jpg";
        myRemoteImages[1]="https://p.xsw88.cn/allimgs/daicuo/20230904/7720.png.jpg";
        myRemoteImages[2]="https://p.xsw88.cn/allimgs/daicuo/20230904/7721.png.jpg";
        myRemoteImages[3]="https://p.xsw88.cn/allimgs/daicuo/20230904/7722.png.jpg";
        myRemoteImages[4]="https://p.xsw88.cn/allimgs/daicuo/20230904/7723.png.jpg";
        myRemoteImages[5]="https://p.xsw88.cn/allimgs/daicuo/20230904/7724.png.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.

在这个网址的图片

https://p.xsw88.cn/allimgs/daicuo/20230904/7725.png.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.

阅读全文

相关推荐

最新文章