如何下载BMP图像并在ImageViewer中显示



我正在尝试下载并在我的android应用程序中显示BMP图片,问题是当我运行应用程序时,根本没有发生变化…如果你能给我点分,那就太好了!:)

堆栈跟踪:http://laravel.io/bin/wOyQ

更新:新代码

public String imageUrl = "http://rory-price.co.uk/uni/images/444444.bmp";
private class LoadTask extends AsyncTask<String,Integer, Bitmap>
{
    @Override
    protected Bitmap doInBackground(String... params)
    {
        try
        {
            URL urlstring = new URL(imageUrl);
            HttpURLConnection connection = (HttpURLConnection) urlstring.openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            Bitmap myBitmap = BitmapFactory.decodeStream(input);
            return myBitmap;
        }
        catch (IOException e)
        {
            e.printStackTrace();
            return null;
        }
    }
    @Override
    protected void onPostExecute(Bitmap myBitmap) {
        ImageView iv = (ImageView) findViewById(R.id.imageView);
        iv.setImageBitmap(myBitmap);
    }
    @Override
    protected void onPreExecute() {}
}
}

试试这个:

         public String imageUrl = "http://rory-price.co.uk/uni/images/444444.bmp";
 private class LoadTask extends AsyncTask<String,Integer, Bitmap>
 {
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inSampleSize = 1;
    @Override
    protected Bitmap doInBackground(String... params)
    {
      try
      {
        URL urlstring = new URL(imageUrl);
        HttpURLConnection connection = (HttpURLConnection) urlstring.openConnection();
        connection.setRequestMethod("GET");
        connection.connect();
        InputStream input = connection.getInputStream();
        Bitmap myBitmap = BitmapFactory.decodeStream(input, null, bmOptions);
        return myBitmap;
    }
    catch (IOException e)
    {
        e.printStackTrace();
        return null;
    }
}
    @Override
    protected void onPostExecute(Bitmap myBitmap) {
        ImageView iv = (ImageView) findViewById(R.id.imageView);
        iv.setImageBitmap(myBitmap);
    }
    @Override
    protected void onPreExecute() {}
}
}

并确保您的manifest文件中有<uses-permission android:name="android.permission.INTERNET" />

相关内容

  • 没有找到相关文章

最新更新