-1

我有我从另一个项目中复制的代码,它允许你向它传递一个 url,它会返回一张图片......然后你将它设置为一个图像视图,它会显示图片......但在某个地方...它不再显示检索到的图片...你们可以看看这段代码并告诉我是否有问题吗???

点击事件

void NextPic(View v)
{
    picNum++; //int holding what pic number we are on
    Drawable bPic = LoadImageFromWebOperations(picData[]); //picData = String[] with url data in it
    imgView.setImageDrawable(bPic); //Cast earlier in the code
}

获取图片功能

private Drawable LoadImageFromWebOperations(String url)
{
    try
    {
        InputStream is = (InputStream) new URL(url).getContent();
        Drawable d = Drawable.createFromStream(is, "src name");
        return d;
    }
    catch(Exception e)
    {
        //Custom error handler
        uu.SendError(e.getMessage(), "Main.GetPickTask.LoadImageFromWeboperations(String url)");
        return null;
    }
}

LogCat 什么都没有显示...没有发现任何错误...而且图片一直显示为空白...我什至使用 ic_launcher 图形作为占位符,所以看看它是否是 imageview 本身...但显示出来了几秒钟然后变黑

这是我使用的示例 URL http://app.guycothal.com/Funnys/2012722133515231.jpg

4

1 回答 1

0
    private Drawable ImageOperations(Context ctx, String url, String saveFilename) {
        try {
            InputStream is = (InputStream) fetch(url);
            Drawable d = Drawable.createFromStream(is, "src");
            return d;
        } catch (MalformedURLException e) {
            return null;
        } catch (IOException e) {
            return null;
        }
    }
    public Object fetch(String address) throws MalformedURLException,IOException {
        URL url = new URL(address);
        Object content = url.getContent();
        return content;
    }
于 2012-07-25T04:55:15.093 回答